2

我对 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 尝试了许多不同的方法,但没有任何运气。

4

1 回答 1

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 输出与预期的一样。

于 2013-06-12T16:08:48.057 回答