Help WebSevice PHP

Folks,
Am new to use webservice in PHP and when I call __soapCall () function always returns a value to me as if he had not passed the username and password . But when I put the information in SOAPUI works, what am I doing wrong ??? how do I get the correct return PHP ? I think the code that understand how you had not managed to pass the parameter …

XML

[php]<s:schema elementFormDefault=“qualified” targetNamespace=“http://www.exemplo.com.br/ws”>
<s:element name=“AutenticarUsuario”>
<s:complexType/>
</s:element>
<s:element name=“AutenticarUsuarioResponse”>
<s:complexType>
<s:sequence>
<s:element minOccurs=“0” maxOccurs=“1” name=“AutenticarUsuarioResult” type=“s:string”/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name=“AutenticacaoHeader” type=“tns:AutenticacaoHeader”/>
<s:complexType name=“AutenticacaoHeader”>
<s:sequence>
<s:element minOccurs=“0” maxOccurs=“1” name=“User” type=“s:string”/>
<s:element minOccurs=“0” maxOccurs=“1” name=“Password” type=“s:string”/>
<s:element minOccurs=“0” maxOccurs=“1” name=“TokenAutenticado” type=“s:string”/>
<s:element minOccurs=“0” maxOccurs=“1” name=“Email” type=“s:string”/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>

[/php]PHP

[php]$client = new SoapClient(“http://www.phphelp.com/PoweredBy/PoweredByWebService.asmx?WSDL”);

$params = new StdClass();
$params = array( “User”=>"‘fabio’",
“Password”=>"‘123456’",
“Email”=>"‘[email protected]’");

$result = $client->__soapCall(“AutenticarUsuario”, $params);

print_r($result);

[/php]Retorno PHP

stdClass Object ( [AutenticarUsuarioResult] => wrong password or user invalid!!! )

SOAP Request

[php]<soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope” xmlns:ws=“http://www.phphelp.com/ws”>
soap:Header
ws:AutenticacaoHeader

ws:Userfabio</ws:User>

ws:Password123456</ws:Password>

ws:Emailfabio[member=4121]phphelp[/member].com</ws:Email>
</ws:AutenticacaoHeader>
</soap:Header>
soap:Body
ws:AutenticarUsuario/
</soap:Body>
</soap:Envelope>

[/php]SOAP Result
[php]<soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
soap:Body

d2149dc5-ce6f-472d-9a83-b950ce3c3f27

</soap:Body>
</soap:Envelope>[/php]

Well, I know little about this, but, in every example I have researched on PHP.net, they do not call it this way:
$result = $client->__soapCall(“AutenticarUsuario”, $params);
In all of the samples they do it this way:
$result = $client->__soapCall(“AutenticarUsuario”, array($params));

$params is already an array, but, the soap call for some reason looks for the nested arrays. Hmmmm?

I changed the code for

  $client = new SoapClient("http://www.phphelp.com/PoweredBy/PoweredByWebService.asmx?WSDL");

$params = new StdClass();
$params = array( “User”=>"‘fabio’",
“Password”=>"‘123456’",
“Email”=>"‘[email protected]’");

$result = $client->__soapCall(“AutenticarUsuario”, array($params));

print_r($result);

But still did not work , is it something about the parameters of passage of the complex type ?

Is the URL you are using correct? Just noticed it.
I could not verify it. It is the PHP.help page, but, this is not a soap server as far as I know. Where did you get it
from? Soap may not be what you think it is. What are you attempting to do with this code? Below is a link to
explain what it is. As you see, you have a client (your code) and a server-side code that sends out the object
based on the client’s request for data. You can’t just send that request out to just any page. Certainly not a
URL page that you listed in your sample code.

Maybe you should tell us what you are trying to do with it.
http://www.techrepublic.com/article/an-introduction-to-the-simple-object-access-protocol-soap/

The WSDL correct is http://www.alcasoft.com.br/PoweredBy/PoweredByWebService.asmx?WSDL

That is not what you posted above. So, what is your error you get back now?

A quick peek at that URL shows that there is no password needed to read the file. It is open to the public.
Therefore, you do not need to request access with a username and password. You just access it’s data.

In this case, since SOAP is really just XML, you could just use PHP XML library to, but, to do this using the
SOAP client, you can access the data by just knowing the data you want to pull from it. Here is a sample to
pull out just one entry. It is nothing important by itself, but, should help you understand how it works. Just
look at the URL you posted online and review the current live page it returns. Then, alter the data you need
inside the $params variable array to include the data you want. Add array items to pull out nested data.

Hope this helps…
[php]

<?PHP $params = array( "name"=>"CadastroPessoaFisica" ); $client = new SoapClient("http://www.alcasoft.com.br/PoweredBy/PoweredByWebService.asmx?WSDL"); $result = $client->AutenticarUsuario($params); print_r($result); [/php]

Within the “CadastroPessoaFisica” method , like all methods of XML , there is a header and body , the header need a username and password , and the body are the parameters of XML .
The first method of XML “AutenticarUsuario” asks username and password, and that it returns " AutenticarUsuarioResult " which is a tokem that is used naos other requests.

Exemple SOAP request “CadastroPessoaFisica”:

<soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope” xmlns:ws=“http://www.alcasoft.com.br/ws”>
soap:Header
ws:AutenticacaoHeader

ws:user?</ws:user>

ws:password?</ws:password>

ws:Token?</ws:Token>

ws:Email?</ws:Email>
</ws:AutenticacaoHeader>
</soap:Header>
soap:Body
ws:CadastroPessoaFisica
ws:ClienteID?</ws:ClienteID>
ws:EmpresaID?</ws:EmpresaID>

ws:Nome?</ws:Nome>

ws:Fantasia?</ws:Fantasia>
ws:Sexo?</ws:Sexo>
ws:EstadoCivilID?</ws:EstadoCivilID>
ws:DtNascimento?</ws:DtNascimento>

ws:CPF?</ws:CPF>

ws:RG?</ws:RG>

ws:CEP?</ws:CEP>

ws:Bairro?</ws:Bairro>

ws:Endereco?</ws:Endereco>

ws:Numero?</ws:Numero>

ws:Complemento?</ws:Complemento>

ws:DDITelefoneResidencial?</ws:DDITelefoneResidencial>

ws:DDDTelefoneResidencial?</ws:DDDTelefoneResidencial>

ws:NumeroTelefoneResidencial?</ws:NumeroTelefoneResidencial>

ws:DDITelefoneCelular?</ws:DDITelefoneCelular>

ws:DDDTelefoneCelular?</ws:DDDTelefoneCelular>

ws:NumeroTelefoneCelular?</ws:NumeroTelefoneCelular>

ws:Email?</ws:Email>

ws:EmailNFe?</ws:EmailNFe>
</ws:CadastroPessoaFisica>
</soap:Body>
</soap:Envelope>

No,
[php]

ws:user?</ws:user>

ws:password?</ws:password>

ws:Token?</ws:Token>

ws:Email?</ws:Email>[/php]

See the comment. That means, not required.

Thanks, please post all code inside the PHP tags. Makes our life easier…

Now, back to the top of your code, you used “User” and “Password”, but, in the last post, you will notice that
the values are “user” and “password”. I do think the capitals are important. Make them small letters…

Yes, the user and password are optional. Not needed. Just use my code and add in whatever you want to
pull out of the file…

Despite the user and password are optional , to request work are essential , because only with these values ​​consiguimos have the return operation

Sponsor our Newsletter | Privacy Policy | Terms of Service