I'm need a little help about WS SOAP Client in PHP.
I have a WS SOAP, restrict to my IP, but I don know almost anything about SOAP, I've already use SOAP with rails a long time ago.
If I access the SOAP server from my browser using this: http://thedomain.com/wssitedsv/site.asmx/RetornaGanhadores
The server return me the correct XML.
If I access the SOAP server from my browser using this:
http://thedomain.com/wssitedsv/site.asmx?wsdl
The server return a xml with configuration of the SOAP
In the PHP I'm doing it:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->RetornaGanhadores(NULL);
echo $return;
And I'm getting this error:
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Users/sidnei/Sites/suasorte/scripts/get_data.php:15
\\nStack trace:
\\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://192.168....', 'https://www.tte...', 1, 0)
\\n#1 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->__call('RetornaGanhador...', Array)
\\n#2 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->RetornaGanhadores(NULL)
\\n#3 /Users/sidnei/Sites/suasorte/index.php(2): include('/Users/sidnei/S...')
\\n#4 {main}
\\n thrown in /Users/sidnei/Sites/suasorte/scripts/get_data.php on line 15
I can get all methods from Server using this:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->__getFunctions();
print_t $return;
What I am doing wrong to use this SOAP server?
How use a SOAP Server in PHP?
I appreciate any help.
Thanks
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'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.
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);
I am using soap call request to below URL using PHP SoapClient.
https://stagingxml.tamarindtours.in/Version1.0/BaseDetails.svc?wsdl
I have used follwing code.
$HeaderSecurity = array("UsernameToken"=>array("Username"=>"xxx",
"Password"=>"xxx",
)
);
$client = new SoapClient('https://stagingxml.tamarindtours.in/Version1.0/BaseDetails.svc?wsdl',array('trace' => 1));
$header[] = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",$HeaderSecurity);
$client->__setSoapHeaders($header);
//$client->__setLocation("https://YourTargetLocation/"); if you have wsdl file you don't need to use this line
$REsponse = $client->GetCountries();
I am getting following error.
Fatal error: Uncaught SoapFault exception: [a:InvalidSecurity] An
error occurred when verifying security for the message. in
/opt/lampp/htdocs/wssoap.php:148 Stack trace: #0
/opt/lampp/htdocs/wssoap.php(148): SoapClient->__call('GetCountries',
Array) #1 /opt/lampp/htdocs/wssoap.php(148):
SoapClient->GetCountries() #2 {main} thrown in
/opt/lampp/htdocs/wssoap.php on line 148
Can you please help me out? Thanks.
Server may have an invalid SSL certificate.
If this error is not important for you, try to ignore SSL certificate check as explained here : https://stackoverflow.com/a/8447706/911718 (see comments too about allow_self_signed option)
Edit : Same error as you & error solved at https://stackoverflow.com/a/16794759/911718
I've currently got a web socket server running and working with Ratchet PHP. I'm not at the stage where I want external scripts to communicate with my server. I can successfully push data to it using ZMQ:
push.php
$json = ['name' => 'Joe Bloggs'];
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'Push Notification');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($json));
Then in my webserver script I can send this to a method (onNewPush) to do something with it when the push.php file is run (ran?):
...
$push = $context->getSocket(ZMQ::SOCKET_PULL);
$push->bind('tcp://127.0.0.1:5555');
$push->on('Push Notification', array($pusher, 'onNewPush'));
...
So this works fine, but I'm having trouble trying to receive a response back. I'm trying something like:
pull.php
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_REQ, 'Pull Notification');
$socket->connect("tcp://localhost:5554");
$socket->send('data');
echo $socket->recv();
Then in my server script:
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5554');
$pull->on('message', array($pusher, 'onPull'));
My $pusher variable loads my file which implements a few Ratchet Interfaces. But essentially I'm just returning a string:
public function onPull()
{
return "some data";
}
When running pull.php I get the error:
Fatal error: Uncaught exception 'ZMQSocketException' with message 'Failed to receive message: Not supported' in websockets\pull.php:9 Stack trace: #0 websockets\pull.php(9): ZMQSocket->recv() #1 {main} thrown in websockets\pull.php on line 9
Does anyone know why?
Also what importance does the second parameter on getSocket() have? Just seems like a string which is never used again.
Cheers
UPDATED
In your pull.php file, you've got a REQ socket connecting to a PULL socket. Check out the docs to see compatible socket pairs. In particular, it appears that you want a REQ-REP pair so that your client can request data and your server replies with a response. You'd use PUSH-PULL if your server queues up data ready for the next client, and then your client pulls whatever is next from the queue.
In either event, you cannot connect a REQ socket to a PULL socket or a PUSH socket.
I don't fully understand your use case or communication architecture from the listed code or naming scheme, so I don't know how much more detail I can give than that, feel free to clarify what's going on and I might be able to advise more definitively what socket strategy you should be using.
You have this line in your pull.php:
echo $socket->recv();
Push socket is for sending messages, not receiving them. That's probably where the exception comes from.
Also: The first parameter of method on() on pull sockets should be 'message'.
$pull->on('message', array($pusher, 'onPull'));