PHP SoapClient错误请求XML

时间:2013-06-07 10:30:35

标签: php xml soap soap-client

我遇到SoapClient问题。我必须对服务进行授权,但生成的XML与服务器所期望的不同。

我的授权码:

$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")
);

要授权该服务,我需要具有以下XML:

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>

如何实现呢?我尝试了很多不同的方法,使用SoapVar,SoapHeaders,但没有任何运气。

1 个答案:

答案 0 :(得分:1)

我使用下面的示例中的对象来解决问题:

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

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

$client->Authorize($object);

它对我来说很完美。 XML输出就像预期的那样。