I'm trying to consume a SOAP webservice from a distant server, the wsdl file is located here http://ecolinthcm.pi-asp.de/logaserver/services/UsersService?wsdl
I've been in touch with the developers there but they keep telling me that it works fine so they're not of great help...
I'm using this little piece of code to poke the bear see if it's alive :
$WSDL = "http://ecolinthcm.pi-asp.de/logaserver/services/UsersService?wsdl";
// the file_get_contents methods doesn't change the end result unfortunately
//$data = file_get_contents($WSDL);
//file_put_contents('./wsdl.xml',$data);
//$WSDL = './wsdl.xml';
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$service = new SoapClient($WSDL,array('stream_context' => $context, 'cache_wsdl' => WSDL_CACHE_NONE));
$result = $service->ErmUserBean (array("UserID","Password","TargetUserID"));
print '<pre>';
var_dump($result);
print '</pre>';
As said in the title I get this message in return :
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't find < definitions > in 'WSDL file URI' in C:\Users\username\Documents\EasyPHP-DevServer-14.1VC11\data\localweb\projects\API\index.php:30 Stack trace: #0 C:\Users\username\Documents\EasyPHP-DevServer-14.1VC11\data\localweb\projects\API\index.php(30): SoapClient->SoapClient('WSDL file URI', Array) #1 {main} thrown in C:\Users\username\Documents\EasyPHP-DevServer-14.1VC11\data\localweb\projects\API\index.php on line 30
I've read most post about this errors and therefore tried a lot of variation in my SOAP request. I've also edited my php.ini file so that the line
extension=php_openssl.dll
appears without ";" (comment) before as I could read here.
The error message you get is correct because the WSDL you linked to is invalid. You can download it and feed it to a WSDL validator (e.g. https://www.wsdl-analyzer.com/) and you will see it is invalid and fails with a similar validation message.
The WSDL is invalid because certain namespaces are wrong. For example, the namespace for the WSDL schema is not https://schemas.xmlsoap.org/wsdl/ and neither is https://www.w3.org/2001/XMLSchema the namespace for XML schema. The correct ones are with http:// not https://.
I fixed the namespaces and uploaded a valid WSDL file here: http://filebin.ca/2lByBlPAOvCu/ChangedUsersService.xml. You can compare it with the original file which I saved here: http://filebin.ca/2lBxfIDsyDas/OriginalUsersService.xml and see the differences.
Try using my WSDL file. Feed it to the online validator and to your code and see if it works.
Related
I used Wireshark to capture what my browser was sending to a printer and captured this:
https://pastebin.com/ZgpDVazX
I'm trying to duplicate that in PHP with the SOAP extension and am having some difficulty. Here's my PHP code:
<?php
$client = new SoapClient(dirname(__FILE__) . '/WebPackage/WSDPrinterService.wsdl', ['trace' => 1]);
$client->__setLocation('http://192.168.1.116/WebServices/PrinterService');
$temp = new stdClass();
$temp->DocumentId = 1;
$temp->Compression = 'none';
$temp->Format = 'unknown';
$params = new stdClass();
$params->JobId = 1;
$params->DocumentDescription = $temp;
$params->LastDocument = true;
$params->DocumentData = file_get_contents('filename.pdf');
$client->SendDocument($params);
Here's the error I get:
[30-Dec-2021 12:57:15 America/Chicago] PHP Fatal error: Uncaught SoapFault exception: [] in /home/neubert/test.php:16
Stack trace:
#0 /home/neubert/test.php(16): SoapClient->__call('SendDocument', Array)
#1 {main}
thrown in /home/neubert/test.php on line 16
If I put $client->SendDocument($params) in a try / catch block and do $client->__getLastRequest() / $client->__getLastResponse() I can see the request (https://pastebin.com/9mTEBD2y) / response (https://pastebin.com/ue94kQUZ).
The faultcode part of the response says "SOAP-ENV:VersionMismatch" but the faultstring makes it sound like there could be something else wrong with the request other than just the version. None-the-less I tried to change the SOAP version by adding 'soap_version' => SOAP_1_2 (and SOAP_1_1) to the ['trace' => 1] array. With SOAP_1_2 the request (https://pastebin.com/cZGusCXa) / response (https://pastebin.com/PLfTV8qt) changes a bit as does the error (End of file or no input: Operation interrupted or timed out) but it's still not working and the error is still just as cryptic to me.
The only thing I can figure is that the DocumentData isn't being formatted correctly. Here's the DocumentData part of the good SOAP request:
<pri:DocumentData>
<xop:Include href="cid:0#body"></xop:Include>
</pri:DocumentData>
Here's the DocumentData of hte bad SOAP request:
<ns1:DocumentData>...</ns1:DocumentData>
So maybe that's the issue? If so then it's not clear to me how to make PHP use xop:Include for the attachment.
The WSDL can be found at https://learn.microsoft.com/en-us/windows-hardware/drivers/print/ws-print-v1-1 (do Ctrl + F and find "Print Device Definition V1.0 for Web Services on Devices")
edit: I also tried converting the PDF to a PS as well but that didn't help. I thought that might make a difference because https://learn.microsoft.com/en-us/previous-versions/ff562064(v=vs.85) describes DocumentData as "Document PDL Data" and https://stackoverflow.com/a/39708917/569976 mentions PS and PCL as PDL's but not PDF.
I have wsld url. I have to add custom http request header to authorize for this wsdl. When I try soapclient as following , I get error.
/* userName and password is masked in this question */
$opts = array(
'http'=>array(
"userName:xxxxx\r\n".
"password:xxxxxx\r\n"
)
);
$streamContext = stream_context_create($opts);
$cilent = new SoapClient("https://iflyrestest.ibsgen.com:6013/iRes_Booking_WS/services/AvailabilityPort?wsdl" , array('stream_context' => $streamContext));
Error:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in
Because response is like 'You are not authorized to access this URL...'
Also When I try function 'file_get_content()' with same stream_context, I successfully get content of this url.
How should I use soapclient for this case ?
if you're sure it is a basic authentication, then you can simply use the login and password SoapClient options, instead of stream_context, with your credentials, it should work then.
I am trying to connect to an API using PHP and its built-in SoapClient. I have checked against the url I was given through the ill-formatted documents the client gave and $client->__getFunctions() returns a list of three functions. HelloWorld($name), which responds with Hello ~name~, shows me that I am communicating with the server through the SoapClient call and the URL is correct.
However, when I try to access one of the other methods that __getFunctions() gives me, even after copy/pasting the XML from the docs and putting in my own credentials, I am still being given an Internal Server Error faultstring and 500 as faultcode from the SoapFault object.
I am sure that it is my own XML string that is causing the issue but I cannot for the life of me figure out how. Reaching out to the API provider directly hasn't proven helpful. This is my first time dealing with Soap/Web Services so I am unsure of where to go from here.
I did wget http//xxx.xxx.xxx?wsdl and it returned me what looks like a valid XML response, the same one I get when I go directly to the url in the browser. What should I be looking into in order to solve this issue? All of the past API's I've dealt with have been JSON/RESTful so I feel out of my element trying to debug PHP errors.
Edit
I have slowly deleted parts of my method call and parts of my XML string, trying to trigger a different error or something in order to find what I need to fix. What I have found is that by not passing in my XML string, I get a valid response from the $client->FunctionCall(...). It's an "this isn't right" message but it's a message! In fact, passing that function ANYTHING for the xml parameter causes the 500 http faultcode/faultstring. Does this mean that my XMl is poorly formatted or does it mean that there is an issue on their end handling requests?
Second Edit
If I make my $client decleration as follows, I get the faultstring Could not connect to host
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
$client = new SoapClient($CREDS['orderingWSDL'], array (
"encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts),
'exceptions'=>true,
));
I am getting more confused the longer I try to fix this.
Sometimes a 500 status coming from a SOAP service could be a SoapFault exception being thrown. To help your troubleshooting, you'll want to be able to inspect both your request XML, and the response XML.
Put your code in try/catch blocks, and use $client->__getLastRequest() and $client->__getLastResponse() to inspect the actual XML.
Example:
$client = new SoapClient('http//xxx.xxx.xxx?wsdl', array('soap_version'=>SOAP_1_1,'trace' => 1,'exceptions' => true));
try {
$response = $client->someFunction();
var_dump($response);
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());
}
There is a web service URL which returns a country's cities details. I can access this web service URL in browser by direct Http Request using GET method
and works fine :
[Snip: I changed my actual domain name with example]
http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>
But when I try to access above URL via SoapClient :
/* Line 36 */
$cities = new SoapClient("http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>");
Gets me following error :
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't find <definitions> in 'http://alpha.example.com/WSV2/StaticData.php?xml=
<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username>
<Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData>
<ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>'
in /srv/www/htdocs/test/inc/client.php:36 Stack trace: #0 /srv/www/htdocs/test/
inc/client.php(36): SoapClient->SoapClient('http://alpha.ex...') #1 /srv/www/
htdocs/ortmas/index.php(6): InitData->getCities(67) #2 {main} thrown in /srv/
www/htdocs/test/inc/client.php on line 36
You must pass the URL to the WSDL, instead of the actual call itself.
Something like that for example :
$cities = new
SoapClient("http://alpha.example.com/WSV2/StaticData.wsdl");
If that url worked on your browser, you can try to do the following in PHP :
$url = "http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>";
$data = file_get_contents($url);
For days now, I've an error and no way to find a solution to fix this.
<SOAP-ENV:Envelope><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>WSDL</faultcode><faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.com/?wsdl' : Premature end of data in tag html line 1
For information, this wsdl work in our production environment, when I try to get it work on my dev environment we got this error.
First, I tried to try this file with SOAP UI, got exactly the same
error.
I tried to exploit it with an external PHP script, same error.
For example :
$wsdl = "http://www.domain.com/?wsdl";
$service = new Soapclient($wsdl);
$params = array('username' => 'xxx', 'password' => 'xxx');
var_dump($service->__soapCall('myFunction', $params));
I tried to use NuSOAP library like some people seem to fix it with
this, it doesn't for me.
I checked firewall
I tried these solution https://bugs.php.net/bug.php?id=49226 none
work
I checked my php.log :
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://www.domain.com/?wsdl' : Premature end of data in tag html line
1 in /data/srv/www/.../library/Zend/Soap/Server.php on line 762
Did some search about this and didn't find any solution to fix it.
Did I miss something ? Have you any idea how to fix this ?
If you need more information, just ask.
Thanks in advance for your help.
load the API from your server.
download the wsdl/xml on your server,
point your $wsdl => point to server file/