Sending XML in SOAP with PHP - php

I'm want to send the following XML file to http://lite.realtime.nationalrail.co.uk
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes" xmlns:typ="http://thalesgroup.com/RTTI/[put your version here]/ldb/types">
<com:AccessToken>
<com:TokenValue>XXXXXXXXXXXXXXXXXXXX</com:TokenValue>
</com:AccessToken>
<typ:GetDepartureBoardRequest>
<typ:numRows>10</typ:numRows>
<typ:crs>MAN</typ:crs>
</typ:GetDepartureBoardRequest>
But I'm not really getting anywhere, nearest I get to any data is a HTTP Error 405

Did you try using the native SoapClient class in order to send a SOAP request? It requires that you define the WSDL path. Then each parameter can be sent with an array or objects.
In order to ease you all this you could use a WSDL to php generator such as WsdlToPhp at wsdltophp.com

Related

How can I get Soap request and response xml through Soap server

Is there any way to get SOAP request and response through SOAP server. I know that I can get it via SOAP client?
Any help will be appreciated.
I am able to get the request xml on my SOAP server, we can get it via following line:-
file_get_contents('php://input')
This provide us the Raw POST data.
But still struggling with response xml.Hope to find a solution for that too.
At the end of the day, a SOAP call is just http.
To get the raw SOAP XML request, use the PHP function http_get_request_body() or use the $GLOBALS['HTTP_RAW_POST_DATA'] variable.
To get the XML response, you can capture it after you do $soapServer->handle(); with $xml = ob_get_contents(); much the same way as you would grab the output of a web page.

Generating schema with soap PHP client

How can I generate this schema using php soap client cant seem to get a way
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/subscribe/manage/v1_0/local">
<soapenv:Header>
<tns:RequestSOAPHeader xmlns:tns="http://www.namesapace.com/common/v2_1">
<tns:one>***</tns:one>
<tns:two>***</tns:three>
<oauth_token>***</oauth_token>
</tns:RequestSOAPHeader>
</soapenv:Header>
<soapenv:Body>
<loc:ProductRequest>
<subInfo>
<productID>***</productID>
<isAutoExtend>0</isAutoExtend>
</subInfo>
</loc:ProductRequest>
</soapenv:Body>
</soapenv:Envelope>
On top of using the client, sometimes it may not bind to the namespace especially if using different soap versions or other strange reasons. Solved it by overriding the soap class and replacing the ns1 and ns2 values as described here http://php.net/manual/en/soapclient.dorequest.php#74123
IF no success with php soapclient, just post the request with curl.
Example in this answer - SOAP request in PHP with CURL

returning soap xml response for a soap server php

I am trying to create a soap service in php using native php soap server. I have already prepared the wsdl file.
There are basically four methods that can be called with the soap service. The input soap request for one of the request ShowRemittanceDetail is shown below.
<soap-env:body>
<ns1:showremittancedetailrequest>
<username>admin</username>
<password>pass</password>
<refno>USA1956127848</refno>
</ns1:showremittancedetailrequest>
</soap-env:body>
Anyway the soap request does not have a header and I have just shown the body here. I have no problem parsing the soap request. The response should look like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns2:responseType xmlns:ns2="http://tempuri.org/response">
<code>00</code>
<message>Transaction does not exist or is not available</message>
<responseBody>
<responseStr>4</responseStr>
</responseBody>
</ns2:responseType>
</soapenv:Body>
</soapenv:Envelope>
This is a particular response which is generated when the transaction with the reference number is not available in the server.
I have received the soap request and evaluated it. However I have a problem with the return type of the soap response. I cannot generate a valid response. What type of response should a soap server return?
Things I have tried:
I have tried returning an xml string. But the soap client request throws an exception with the following message.
looks like we got no xml document.
I have also tried returing a native php SoapVar() with the same result.
I have tried returning an object response that is specified in the classmap fo the soap server.
e.g. for the example above, I have tried returning a ShowRemittanceDetailResponse object with the same result. (looks like we got no xml document).
I have tried returning a DomDocument Object . The exception thrown in this case is
the encoded object does not have a responseStr property.
I have tried returning an stdClass object with the same fields as the response expects with similar result.
Please help me.
Thanks in advance.
The solution I found was returning a SoapVar object. I didnt have soapui and the client I wrote in php was incorrect. Hence, I had problem verifying the returned xml as the php soap client was throwing an exception. The correct way for me was to return a SoapVar.

Autogenerate SOAP requests from WSDL in PHP

Im have searched a lot for a code-snippet to autogenerate a SOAP request based on a WSDL in PHP.
We have a 3'rd party vendor creating a huge WSDL ( + related webservices) for us , and I would really like to autogenerate some SOAP-requests in PHP based on that WSDL.
I know of application specific tools like SOAPUI etc - however - I prefer to do the unittesting directly in the PHP-code.
Do you know of any PHP lib to autogenerate SOAP requests based on a WSDL? Or even better, do you have a some code to autogenerate a SOAP request?
use apigenerator.com to generate soap requests
What i would recommend you is to use the soap components of the zend framework.
For example you just setup a soap client using :
$client = new Zend_Soap_Client("url to wsdl file");
//Then you can do what ever request to the server.
$client->helloWorld("Parameter');
// In this example i guess helloWolrd is a server function.
and finally you can have the xml soap request calling:
$request = $client->getLastRequest();
just do: echo $request; and you will see the data.
Remember to change the mime code to xml so you can see the xml in the browser.

Send XML with SOAP

I need to send SOAP data.
<vodh:VODHeader xmlns:vodh="http://www.example.com/soap/header/">
<vodh:info>getuser</vodh:info>
<vodh:authentication>
<vodh:username>xxx</vodh:username>
<vodh:password>xxx</vodh:password>
</vodh:authentication>
</vodh:VODHeader>
<vodb:VODBody xmlns:vodb="http://www.example.com/soap/body/" version="1.0">
<vodb:idUser>65344</vodb:idUser>
<vodb:message>Lorem ipsum</vodb:message>
</vodb:VODBody>
I was using SoapClient to create an array and pass it as parameter but is well defined so?
$client = new nusoap_client($Urlserver,FALSE);
//$data_xml is the xml I mention in previous lines
$msg = $client->serializeEnvelope($data_xml);
$result=$client->send($msg, $Urlserver);
This is the correct way to send data or other method.
And soap responds with an ACK.

Categories