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.
Related
I am really new to Web Services and xml and I'am Having problems sending xml to a web server
I' am using SoapCliente Php class
$client = new SoapClient($wsdlUrl, $soapClientOptions);
I'm not having any problem sending strings
$param = ["key" => "somekey"];
var_dump($client->somemethod($parms));
But, I am having probles sending xml data as is requered on the web service documentation
#WebParam(name = "xml") byte[] xml);
On the getTypes method:
var_dump($client->__getTypes());
Is specified in this way:
base64Binary xml
So I first stored the xml file as a string variable and then i tried:
$xmlstring = "some xml";
$xmltosend = unpack('C*', $xmlstring);
var_dump($client->somemethod($xmltosend));
And:
$xmlstring = "some xml";
$xmltosend = base64_encode($xmlstring);
var_dump($client->somemethod($xmltosend));
The Web Service always send a response acording to the data so if the send was correct i will get some succes xml data. In both cases I get this error:
FILES SENT NOT COMPLY WITH THE ESTABLISHED SPECIFICATIONS: EXTENSION, CODIFICATION
The xml format that i am sending is provided as a test example by the web service's documentation so i think the xml is Ok, so I am clueless of what I am missing.
Edit
This is exactly how the params are excected on the documentation
#WebMethod
#WebResult(name = "RespuestaRecepcionComprobante")
public RespuestaSolicitud validarComprobante(#WebParam(name = "xml") byte[]
xml);
So i just sended the xml string and it worked
$param = ["xml" => $xmlstring];
var_dump($client->validarComprobante($param));
It's ok to send the data like this?
The web service read the xml and send me an Ok response
I also expect an xml response but I dont know how to catch it
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.
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
I'm a newbie at CI, and I want to retrieve XML data from web services WebLogic, the server that is located at: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA . I want to to get the XML response from the server. How should I do this?
I made this function on controllers (resttest.php)
public function getRest()
{
$this->rest->initialize(array('server' => 'http://services.insw.go.id'));
$lartas = $this->rest->get('web-services/nsw',array('operation.invoke' => 'getListGA'),'xml');
die(var_dump($lartas));
}
Sometimes I get an error like "array(0) { }" and if I refresh, I get all HTML view, the same as when I browse to: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA
Am I wrong, or missing some step, or do you have any suggestion about how to change this code?
It looks as if your webservice is using SOAP (simple object access protocol). This is not REST. You'll want to use PHP's built in Soap extension with the SoapClient class. This way it's easy to post a XML "request" to that page which will return xml results rather than a html view (I assume).
Check Soap the soap extension is loaded on your server
Read about the SoapClient http://php.net/manual/en/class.soapclient.php
See if that webservice offers a WSDL (web service description language) file.
Create an instance of a soap client, using the wsdl and call the function you require.
Simple example from PHP.net
$client = new SoapClient("http://localhost/code/soap.wsdl");
$something = $client->HelloWorld(array());
echo $something->HelloWorldResult;
To get a xml response, you do not need Codeigniter. Specifically it provide WSDL. At http://services.insw.go.id/web-services/nsw you can find the example as
String wsdlUrl = "http://services.insw.go.id:80/web-services/nsw?WSDL";
So the WSDL API would be http://services.insw.go.id:80/web-services/nsw?WSDL
Then you can check this page to see how to install soap for your php.
Then you can get a xml response by the following code:
$client = new SoapClient('http://services.insw.go.id:80/web-services/nsw?WSDL');
//var_dump($client->__getFunctions());
$response = $client->getListGA();
echo $response;
these code do not need Codeigniter.
Note: $client->__getFunctions() will show you all functions that the WSDL support and the parameters the functions need.
Good luck
I'm sending a SOAP request that looks like:
<SOAP-ENV:Body>
<api:GetOrder xsi:type="SOAP-ENC:Struct">
<api_orderId xsi:type="xsd:int">1234</api_orderId>
</api:GetOrder>
</SOAP-ENV:Body>
But needs to look like this (SoapUI generated):
<soapenv:Body>
<api:GetOrder>
<api:orderId>1234</api:orderId>
</api:GetOrder>
</soapenv:Body>
My PHP Code:
$client = $this->getConnection();
$soap_options = array('soapaction' => $config->getValue('soapaction_url') . 'GetOrder');
$obj = new stdClass();
$obj->api_orderId = 59698;
$results = $client->__soapCall('GetOrder', array(new SoapParam($obj, "api:GetOrder")), $soap_options);
2 questions really:
1) How can I remove the "xsi:type" from the request? (If I add xsi:type in to my SoapUI request, I get back a "400 Bad Request"
2) Instead of "api_orderId" I need to send "api:orderId", but I can't name an object with a colon, so do I have to pass the name and value as an array somehow?
Appreciate any help, thank you.
EDIT:
I wasn't able to figure out any other way to send these requests and I essentially ended up doing as Mr.K suggested below.
I wrote a custom class to extend SoapClient. Then overrode the __doRequest method to send my own custom SOAP request.
The only downside is that SOAP no longer returns me an array of objects, so I also had to parse the XML of the SOAP response.
Also I suspect that the performance of doing it this way is a bit slower, but I didn't notice it.
Try with Simple XML parsing, and create the new request as you like.
Read the tag values from Original request, assign those values to a new XML object using parsing. You can create string of XML message and load it as an XML object in PHP.
Just like get it from there, put it inside this..and Send!..