2

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.

1
  • What specifically does not work for you? What XML is the generated by your PHP code in question? Commented Jun 7, 2013 at 11:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.