Juliano Ranite
Juliano Ranite

Reputation: 1

Sending and requesting SOAP

I'm trying to use an example that I found on the internet to send and receive from xml to a SOAP url, but I could not understand very well how SOAP works.

Can anyone help me? Here is the code that I'm passing:

$xml = <<<XML
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cad="http://servicos.saude.gov.br/cadsus/v5r0/cadsusservice" xmlns:cnes="http://servicos.saude.gov.br/wsdl/mensageria/v5r0/cnesusuario" xmlns:fil="http://servicos.saude.gov.br/wsdl/mensageria/v5r0/filtropesquisa" xmlns:nom="http://servicos.saude.gov.br/schema/corporativo/pessoafisica/v1r2/nomecompleto" xmlns:nom1="http://servicos.saude.gov.br/schema/corporativo/pessoafisica/v1r0/nomefamilia" xmlns:cpf="http://servicos.saude.gov.br/schema/corporativo/documento/v1r2/cpf" xmlns:mun="http://servicos.saude.gov.br/schema/corporativo/v1r2/municipio" xmlns:uf="http://servicos.saude.gov.br/schema/corporativo/v1r1/uf" xmlns:tip="http://servicos.saude.gov.br/schema/corporativo/documento/v5r0/tipodocumento"><soap:Header><wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-F6C95C679D248B6E3F143032021465917"><wsse:Username>CADSUS.CNS.PDQ.PUBLICO</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">kUXNmiiii#RDdlOELdoe00966</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">KkB/ki6qUjcZpGNqL4monw==</wsse:Nonce><wsu:Created>2015-04-29T15:10:14.659Z</wsu:Created></wsse:UsernameToken></wsse:Security></soap:Header><soap:Body><cad:requestPesquisar><cnes:CNESUsuario><cnes:CNES>6963447</cnes:CNES><cnes:Usuario>LEONARDO</cnes:Usuario><!--Optional:--><cnes:Senha>?</cnes:Senha></cnes:CNESUsuario><fil:FiltroPesquisa><fil:CPF><cpf:numeroCPF>66105234368</cpf:numeroCPF></fil:CPF><fil:tipoPesquisa>IDENTICA</fil:tipoPesquisa></fil:FiltroPesquisa><cad:higienizar>0</cad:higienizar></cad:requestPesquisar></soap:Body></soap:Envelope>
XML;

$wsdl = 'https://servicoshm.saude.gov.br/cadsus/CadsusService/v5r0?wsdl';
$client = new SoapClient($wsdl, array(
    'cache_wsdl'    => WSDL_CACHE_NONE, 
    'cache_ttl'     => 86400, 
    'login'=> "CADSUS.CNS.PDQ.PUBLICO",
    'password'=> "kUXNmiiii#RDdlOELdoe00966",
    'trace'         => true,
    'exceptions'    => true,
));

$xmlVar = new SoapVar($xml, XSD_ANYXML);
$client->getCustomerInfo($xml);

Error:

Fatal error: Uncaught SoapFault exception: [Client] Function ("getCustomerInfo") is not a valid method for this service in /home/itconect/www/sisam/testeJ.php:18 Stack trace: #0 /home/itconect/www/sisam/testeJ.php(18): SoapClient->__call('getCustomerInfo', Array) #1 /home/itconect/www/sisam/testeJ.php(18): SoapClient->getCustomerInfo('

I have another doubt in this code. Would I receive the result or do I have to supplement it with something yet?

Upvotes: 0

Views: 402

Answers (1)

Felix
Felix

Reputation: 575

If you are using the WSDL of your code, than this SOAP service does not have a method called "getCustomerInfo". The methods according to the WSDL are pesquisar, consultar, incluir, atualizar, alterarSituacao and calcularGrauDeQualidade.

I'd also recommend using the php helpers instead of writing xml yourself (Examples: How to make a PHP SOAP call using the SoapClient class).

Edit: A very basic example

<?php

$wsdl = 'http://www.webservicex.net/BibleWebservice.asmx?WSDL';
$client = new SoapClient($wsdl, array(
    'cache_wsdl'    => WSDL_CACHE_NONE,
    'trace'         => true,
    'exceptions'    => true,
 ));

$keyword = new StdClass();
$keyword->BibleWords = "god";

$result = $client->GetBibleWordsbyKeyWord($keyword);

var_dump($result);

Upvotes: 1

Related Questions