Sending raw XML with php nusoap client

In my last blog post I described how to use wsdl2php to parse a wsdl file and generate php classes. This should make your life a lot simpler when dealing with SOAP Web Services.

But there are times that all the frameworks and toolkits in the world wont be able to produce the desired plain XML structure of the SOAP call. Especially when you are working with Chinese low-end equipment.

I usually work in php nusoap and I had trouble finding the right way to do this. I was so desperate, that I have been posting raw XML with CURL to mimic the SOAP Request. Luckily I found a way to do i with our favourite php soap toolkit.

Thow following is an example that calls a function insertUser with raw XML:


require_once('nusoap/lib/nusoap.php');

$endpoint = "http://yoursoapserver.com/SomeSoapService";

$client = new nusoap_client($endpoint, false);

$msg = $client->serializeEnvelope("
<ns1:insertuser xmlns:1="http://yoursoapserver.com/">
  <arg0 xsi:type="xsd:string">name</arg0>
  <arg1>
    <username xsi:type="xsd:string">username</username>
    <password xsi:type="xsd:string">0ac495f743a36cef9b0eaafa92ae08e21</password>
  </arg1>
  <arg2 xsi:type="xsd:string">email</arg2>
  <arg3 xsi:type="xsd:string">domain</arg3>
</ns1:insertuser>
");

$result=$client->send($msg, $endpoint);

print_r($result);

4 comments:

  1. Could you please post a server example to the above code.

    ReplyDelete
    Replies
    1. What do you mean by a server example? I have usually used this when I have worked with predefined SOAP servers

      Delete
  2. hi i m used the same code but i got error "Response not of type text/xml: text/html; charset=UTF-8" any idea why this occurred . i am using 3 party web services

    ReplyDelete
  3. hi i saw your webservice article its nice. i have question regarding soap webservice i want to use dot.net soap webservice in my php soap service . do u have any idea how can i acheive it . thanks

    ReplyDelete