Can anyone tell me a reason the following code shouldn't work, assuming it points to the right external files and calls the correct functions?
<?php
$xmlstr = simplexml_load_file("file.xml");
$wsdl = 'file.wsdl';
$client = new SoapClient($wsdl, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));
$xmlVar = new SoapVar($xmlstr, XSD_ANYXML);
$client->DoFunction($xmlstr);
The xml file it points to is an exact output of what i should send the server to get a response but all I get is an error 'Fatal error: Uncaught SoapFault exception' talking about the header can't be null. Which sounds like it isn't getting the authentication details but they are all correct. Is there anything I'm obviously doing wrong here?
Related
I would like to remove ns:1 and ns:2 from my Soap request.
Actually I got this when it is generated:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="*********" xmlns:ns2="**************"><SOAP-ENV:Header><ns2:shp:sc><user>***</user><password>*******</password><companyName>******</companyName><autoCommit>***</autoCommit></ns2:shp:sc></SOAP-ENV:Header><SOAP-ENV:Body><ns1:p_put_order><put_orderRequest><shop_order>TEST2</shop_order><shop_account>100000</shop_account><order_comment>test</order_comment></put_orderRequest></ns1:p_put_order></SOAP-ENV:Body></SOAP-ENV:Envelope>
Then in my php file, I got :
$options = array("soap_version" => SOAP_1_1,
"encoding" => "UTF-8",
"trace" => true,
"exceptions" => true,
'cache_wsdl' => WSDL_CACHE_NONE,
);
$client = new SoapClient($soapURL, $options);
$header = new SoapHeader($soapURL,'shp:sc',$auth, false);
$headerSoap = $client->__setSoapHeaders($header);
I tried to use, SoapVar(), __doRequest() and none of those works ...
Have you got an idea about that ?
Thank you for your help
$header = new SoapHeader($soapURL,'shp:sc',$auth, false);
Please remove $soapURL from here. First argument is suppose to be namespace. Please see documentation here: http://php.net/manual/en/class.soapheader.php . If this fail please post WSDL file.
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?
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);
Im trying to make this fixed, but im stuck. Im not very skilled with WSDL, SOAP and making an XML with it. I'll keep getting this error "Operation '' is not defined in the WSDL for this service" Did anyone know how did i get rid of this error? My goal is to get an XML with all the occasions from a car garage and put them in my database.
This is my code:
ini_set('soap.wsdl_cache_enabled', 1);
$options = array(
'soap_version' => SOAP_1_2,
'trace' => true,
'exceptions' => true,
'encoding' => 'UTF-8',
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'cache_wsdl' => WSDL_CACHE_DISK,
'login' => '****', // <- username here, i got the right one
'password' => '****' // <- same
);
try{
$client = new SoapClient('https://eigenwebsite.doorlinkenvoorraad.nl/v1/leads/deliver.html?wsdl', $options);
//var_dump($client->__getFunctions());
//echo '<br>';
$klant = array(
"key"=>"****", // got the right one
"klantnummer"=>"****", // got the right one
"lead"=>"information_request",
"testmode"=>"dummy"
);
$quote = $client->deliverLead($klant);
}catch(SoapFault $exception){
echo $exception->getMessage();
}
Try changing the SOAP version to 1.1:
'soap_version' => SOAP_1_1,
The web service only supports SOAP 1.1 from the looks of the WSDL, so it is throwing an error when you send it a SOAP 1.2 message.
I've got error: Unable to handle request without a valid action parameter.
I want to just login by SOAP server.
My wsdl is here: https://demo.krd.pl/Siddin/2.1/Import.asmx?WSDL
and my code is like:
$client = new SoapClient('https://demo.krd.pl/Siddin/2.1/Import.asmx?WSDL', array(
'location' => 'https://demo.krd.pl/Siddin/2.1/Import.asmx?WSDL',
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'soap_version' => SOAP_1_2
));
$auth = new stdClass();
$auth->UserName = 'aaa';
$auth->Password = 'bbb';
$auth = new SoapVar($auth, SOAP_ENC_OBJECT, 'complexType', null, 'LoginRequest', 'types');
$result = $client->login($auth);
die(var_dump($result));
As You can see, I want to invoke method 'login' on this SOAP server with parameter LoginRequest - it's described in wsdl file. How do that?
without a valid action parameter.
This means that your php soap client is not able to make up the needed SOAPAction http header. You WSDL defines for login method this:
soapAction="http://Siddin.ServiceContracts/2006/09/Login"
There are a number of reasons possible for it not to add the header, e.g. this one:
'soap_version' => SOAP_1_2,
Try changing it to
'soap_version' => SOAP_1_1,
In case that doesnt resolve it, i recommend you to start general soap debugging by tracing the message being sent (including http headers) and compare it to a working request that you can set up e.g. using SoapUI https://www.soapui.org/
I'd like to make a soap call to the eBay api and finds products by keywords. With the help of eBay documentation and other online resources, I came up with this code:
$client = new \SoapClient('http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl');
$soap_headers = array(
new \SoapHeader('X-EBAY-SOA-OPERATION-NAME', 'findItemsByKeywords'),
new \SoapHeader('X-EBAY-SOA-SERVICE-VERSION', '1.3.0'),
new \SoapHeader('X-EBAY-SOA-REQUEST-DATA-FORMAT', 'XML'),
new \SoapHeader('X-EBAY-SOA-GLOBAL-ID', 'EBAY-US'),
new \SoapHeader('X-EBAY-SOA-SECURITY-APPNAME', '<there would be the key>'),
);
$client->__setSoapHeaders($soap_headers);
// Call wsdl function
$result = $client->__soapCall("findItemsByKeywords", array("keywords" => "Potter"));
However, this code results in an error:
"Service operation is unknown,
500 Internal Server Error - SoapFault"
I tried changing the first line into this (don't know why it should make a difference, but I saw it somewhere):
$client = new \SoapClient(NULL, array(
"location" => 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1',
'uri' => 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1')
);
And now this result in this error: Missing SOA operation name header,
500 Internal Server Error - SoapFault
Does anybody know what causes these errors to occur and how to fix them?
Thank you, Mike!
The following code works.
define('APP_ID', '*** Your App ID ***');
$wsdl = 'http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl';
// For sandbox
$endpoint_uri = 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1';
// For production
//$endpoint_uri = 'http://svcs.ebay.com/services/search/FindingService/v1';
// We'll use this namespace explicitly for the 'keywords' tag,
// because the SoapClient doesn't apply it automatically.
$ns = 'http://www.ebay.com/marketplace/search/v1/services';
// The SOAP function
$operation = 'findItemsByKeywords';
$http_headers = implode(PHP_EOL, [
"X-EBAY-SOA-OPERATION-NAME: $operation",
"X-EBAY-SOA-SECURITY-APPNAME: " . APP_ID,
]);
$options = [
'trace' => true,
'cache' => WSDL_CACHE_NONE,
'exceptions' => true,
'location' => $endpoint_uri,
//'uri' => 'ns1',
'stream_context' => stream_context_create([
'http' => [
'method' => 'POST',
'header' => $http_headers,
]
]),
];
$client = new \SoapClient($wsdl, $options);
try {
$wrapper = new StdClass;
$wrapper->keywords = new SoapVar('harry potter', XSD_STRING,
null, null, null, $ns);
$result = $client->$operation(new SoapVar($wrapper, SOAP_ENC_OBJECT));
var_dump($result);
} catch (Exception $e) {
echo $e->getMessage();
}
As already mentioned, one of the issues is that you pass X-EBAY-SOA-* values as SOAP headers. The service expects them as HTTP headers:
HTTP Headers or URL Parameters—Each Finding API call requires certain
HTTP headers or URL parameters. For example, you must specify your
AppID in the X-EBAY-SOA-SECURITY-APPNAME header or SECURITY-APPNAME
URL parameter. Similarly, you must always specify the call name in the
X-EBAY-SOA-OPERATION-NAME header or OPERATION-NAME URL parameter.
Other headers are optional or conditionally required.
The second issue is that the SoapClient location option is not specified. It should contain an URI to one of the service endpoints. Otherwise, the API returns Service operation is unknown error.
Finally, the SoapClient doesn't put the keywords into Ebay's namespace:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.ebay.com/marketplace/search/v1/services">
<SOAP-ENV:Body>
<ns1:findItemsByKeywordsRequest>
<keywords>harry potter</keywords>
</ns1:findItemsByKeywordsRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As a result, the API returns an error: Keywords value required.. So I've specified the namespace for the keywords tag explicitly.
Also note the use of different endpoint URIs for sandbox and for production.
The thing is, the service expects HTTP Headers (or query string parameters, apparently, by reading their guide a bit).
With __setSoapHeaders you are, well, setting SOAP Headers.
Try this, for instance
$wsdl = 'http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl';
$appID = 'YOUR KEY/ID';
$headers = implode(PHP_EOL, [
"X-EBAY-SOA-OPERATION-NAME: findItemsByKeywords",
"X-EBAY-SOA-SECURITY-APPNAME: $appID"
]);
$options = [
'trace' => true,
'cache' => WSDL_CACHE_NONE,
'exceptions' => true,
'stream_context' => stream_context_create([
'http' => [
'header' => $headers
]
]),
];
$client = new SoapClient($wsdl, $options);
$response = $client->findItemsByKeywords([
'keywords' => 'Potter'
]);