Sending XML string (not array) from PHP SOAP or nusoap to .NET service
Solution 1
You can send plain XML with the $client->send() method.
$raw_xml = "<Your_XML>...</Your_XML>";
$msg = $client->serializeEnvelope("$raw_xml");
$result=$client->send($msg, $endpoint);
You can see the example here:
http://itworkarounds.blogspot.com/2011/07/send-raw-xml-with-php-nusoap.html
If that does't work you can try posting the XML with CURL.
Solution 2
-try this-
$xml = simplexml_load_string('<data>x</data>')
and then (nusoap)
$result = $client->call('host', array('parameter' =>$xml)
Solution 3
Not exactly an answer to the issue - but it is now solved. The service provider created a new method, which was identical in all respects except that it allowed for an XML document rather than a string. By making some minor alterations to the contents of the $bodyxml variable, and sending to this new method, it appears to work fine.
By the way - anyone looking to debug SOAP applications should really look at grabbing SOAP UI off Sourceforge. This really helped me sanity check my issue, and provided some useful pointers for the fix.
odeclas
Updated on August 05, 2020Comments
-
odeclas almost 4 years
I'm new to SOAP and I'm having issues (yes, I have searched - extensively, but I can't seem to match my very simple requirement - sending a single XML string) with sending some output to a .NET server to match this:
POST /someurl.asmx HTTP/1.1 Host: www.somehost.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://somehost.com/SubmitCalls" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <SubmitCalls xmlns="http://somehost/"> <request>string</request> </SubmitCalls> </soap:Body> </soap:Envelope>
My nusoap code looks like this:
<?php require_once('../lib/nusoap.php'); $bodyxml = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <SubmitCalls xmlns="http://somehost/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <request> <?xml version="1.0" encoding="UTF-8"?> <bXML xmlns="http://somehost/Schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <From> <UserName>some username</UserName> <Password>some password</Password> </From> <Calls> <Call> <Reference>11111</Reference> <Name>Joe Bloggs</Name> <Tel1>02075574200</Tel1> <Tel2>02075574201</Tel2> <Tel3>02075574202</Tel3> <Tel4>02075574203</Tel4> <Tel5>02075574204</Tel5> <CLI>08448220640</CLI> <CallTime>09:00</CallTime> <FileName>02075574200_1</FileName> </Call> <Call> <Reference>11111</Reference> <Name>Joe Bloggs</Name> <Tel1>02075574200</Tel1> <Tel2>02075574206</Tel2> <Tel3>02075574207</Tel3> <Tel4>02075574208</Tel4> <Tel5>02075574209</Tel5> <CLI>08448220640</CLI> <CallTime>09:00</CallTime> <FileName>02075574200_2</FileName> </Call> </Calls> </bXML> </request> </SubmitCalls> </soap:Body> </soap:Envelope> '; $client = new nusoap_client("somehost?WSDL",true); $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; exit(); } $client->soap_defencoding = 'utf-8'; $client->useHTTPPersistentConnection(); $client->setUseCurl($useCURL); $bsoapaction = "http://somehost/SubmitCalls"; $result = $client->send($bodyxml, $bsoapaction); // Check for a fault if ($client->fault) { echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>'; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo '<h2>Error</h2><pre>' . $err . '</pre>'; } else { // Display the result echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>'; } } echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; echo '<h2>Client Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; echo '<h2>Proxy Debug</h2><pre>' . htmlspecialchars($proxy->debug_str, ENT_QUOTES) . '</pre>'; ?>
(Obiously, all the somehost and usernames are correct in the final script). I can connect to the WSDL, read it, there's only one method I'm interested in (SubmitCalls) which only has one part, named 'parameters' in the WSDL schema. The above throws a 400 Bad request error - any ideas where I'm going wrong?
I've tried using PHP SOAP instead, but I simply can't seem to send an XML string as the body of the SOAP request. I've been fiddling with this for the best part of three days and read a zillion web pages, but I still can't get it right. Please help.... if you could show me how to do this using either library I would be enormously grateful....
-
odeclas over 13 yearsThe SoapAction header is set by the second parameter of the send function, I think (the var bsoapaction in my code). Unless I'm setting it wrong....
-
odeclas over 13 yearsSeriously, any pointers at all on this please? As I seem to generate 400 Bad request errors - what does that mean in this context? Does it mean that the header info is wrong, or the encoding? Or am I doing something with the string that's screwy?
-
odeclas over 13 yearsI've tried using PHP SOAP and __doRequest using the $request that apparently works from a .NET client, and still getting a 400....
-
Byron Whitlock over 13 yearsInstall fiddler, and look at differences between what the .net client sends and what php sends. Or do like i said and send the xml directly bypassing the libraries.