Jack Cotton
Jack Cotton

Reputation: 31

PHP SoapClient wrong request XML

I have a problem with SoapClient. I have to authorize to the service but the XML generated is not like the one expected by the server.

My authorization code:

$options = array( 
  'soap_version' => SOAP_1_1, 
  'exceptions' => true, 
  'trace' => 1, 
  'cache_wsdl' => WSDL_CACHE_NONE,
  'uri' => 'http://tempuri.org/'
);

$client = new SoapClient("http://serviceurl/basic.asmx?wsdl", $options);
$client -> Authorize(
    new SoapParam('testdomain', "domainName"),
    new SoapParam('testuser', "user"),
    new SoapParam('testpassword', "password")
);

To authorize the service I need to have XML like below:

POST /service/basic.asmx HTTP/1.1
Host: testcloud.testhost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Authorize"

<?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>
    <Authorize xmlns="http://tempuri.org/">
        <domainName>string</domainName>
        <user>string</user>
        <password>string</password>
    </Authorize>
</soap:Body>
</soap:Envelope>

How to achieve it? I tried many different ways using SoapVar, SoapHeaders but without any luck.

Upvotes: 2

Views: 1163

Answers (1)

Jack Cotton
Jack Cotton

Reputation: 31

I solve the problem using an object like in example below:

$client = new SoapClient("http://serviceurl/basic.asmx?wsdl", $options);

$object = new stdClass;
$object->domainName = 'testdomain';
$object->user       = 'testuser';
$object->password   = 'testpassword';

$client->Authorize($object);

It works perfecly for me. XML output is like expected.

Upvotes: 1

Related Questions