Php’s SoapClient and the ContentType of the request


half of the last day, I fought with a C# WebService and the PHP SoapClient implementation.
The SoapClient always send it’s requests always with contenttype “text/xml”, but a C# WebService isn’t smart enough to recognize that it is readable xml but just crys: Uh Oh thats not application/soap+xml … I can’t read that!! I’m very sorry!!

But finally I could tell the SoapClient of PHP to send the request in Application/soap+xml by adding the “soap_version” option to the SoapClient. When you use Soap Version < 1.2 the SoapClient implementation sends the request in text/xml, using the Soap Version 1.2 it sends it in application/soap+xml ... Hopefully this helps someone! Ciao Ephraim

This entry was posted in Windows and tagged . Bookmark the permalink.

5 Responses to Php’s SoapClient and the ContentType of the request

  1. Nico says:

    Yes you did help someone 🙂 thanks!

  2. Michael says:

    Man, I was struggling with this one… Thanks!

  3. farzal says:

    Hi – can you possibly share you code

    And also, which version of php and apache are you using?

    I am struggling with the exact issue, but changing to 1_2 does not do any difference to content type

    new nusoap_client(‘wsdl/xyz.wsdl’,true, ”, ”, ‘USER’, ‘PASSWORD’, array(‘soap_version’ => SOAP_1_2));

  4. surge says:

    SOAP_1_2 is for the built in PHP SOAP library (here:

    The nusoap_client is a 3rd party library and there I had to modify their code to pass the correct type.

    Look for getHTTPContentType in nusoap.php within the library (nusoap/lib]/nusoap.php). That’s about line 7995 in version 1.123. Note, the file contains two of those methods. I didn’t really have time to find out what is what, but the last one is what’s needed.

    Add the following method just above it:

    function setHTTPContentType($type) {
    $this->encoding_type = $type;

    then add the following variable as part of class nusoap_base (beginning of the file).

    var $encoding_type = “text/xml”

    The in your code you can do:

    nusoap_client.setHTTPContentType(‘your type’);

    UTF-8 is set with:

    $soapclient->soap_defencoding = ‘UTF-8’;

    Hope it helps.

  5. LornaJane says:

    This saved a *lot* of time, thanks so much for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *