SOAP Fault ; unable to handle - php

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/

Related

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?
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);

Operation '' is not defined in the WSDL for this service

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.

Ebay API returns "Service operation is unknown" and "Missing SOA operation name header" errors when using PHP

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'
]);

PHP - SOAP WSDL

Currently i'm trying to build a little PHP - Soap Connector, which worked pretty good so far. But when i'm deploying my little script to my server, it won't work anymore and i have no clue, why.
I'm connecting in 2 different ways (by curling the SOAP WSDL Scheme, and saving it temporary in the script location, and creating from that a new SOAP Client, and creating a SOAP Client directly by using the SOAP WSDL Scheme URL):
$opts = array(
'http'=>array(
'user_agent' => 'PHP Soap Client'
)
);
$context = stream_context_create($opts);
// SOAP 1.2 client
$params = array (
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 30,
);
$curlStuff = curl_init($soapURL);
curl_setopt($curlStuff,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curlStuff,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curlStuff,CURLOPT_TIMEOUT,30);
$response = curl_exec($curlStuff);
$info = curl_getinfo($curlStuff);
if($response) {
file_put_contents("./tempSoapScheme.wsdl", $response);
}
$soapClient = new SoapClient(
'./tempSoapScheme.wsdl',
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$soapClientTwo = new SoapClient(
$soapURL,
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$result = $soapClient->myLoginMethod(
array(
'username' => 'my#email.example',
'password' => 'password'
)
);
As i said earlier - on my local machine it works like a charm, and everything is fine. The param "soapURL", which is not inside the script, is just the https path to my SOAP WSDL Scheme.
I've tried different options inside "$params" array, other curl setopt settings, but i can't make it work.
The response from both SoapClients:
SOAP-ERROR: Parsing WSDL: Couldn't load from '<MyURL>' : failed to load external entity "<MyURL>", which is pretty uncommon, because the CURL could save everything.
Do you have any suggestions for me?
EDIT - forgot the most important thing:
- The server, which should execute the script, has very strong firewall restrictions, and the SOAP URL Scheme is on another server (not the same). And i guess, that is the point, why it won't work, but i receive an answer from the Scheme by executing CURL.. So it's just SOAP?

Anything wrong with this soapclient request?

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?

Categories