我正在尝试创建正确的基于 wsdl 的肥皂请求,但没有成功,这是我需要的示例: soap.xml:
<?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:Header>
<AuthMember xmlns="http://tempuri.org/">
<somefield>string</somefield>
</AuthMember>
</soap:Header>
<soap:Body>
<AuthenticateMember xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
我的结果是: soap.xml:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.xmlsoap.org/ws/2002/07/utility">
<SOAP-ENV:Header>
<ns2:AuthMember>
<somefield>somefieldvalue</somefield>
</ns2:AuthMember>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:AuthenticateMember/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我的 php 代码:
class SoapHeaderAuthMember
{
public $somefield;
public function __construct($somefield)
{
$this->somefield = $somefield;
}
}
$client = new SoapClient( 'https://www.somepage.com/service.asmx?WSDL',
array("exceptions"=>0, "trace" => 1 )
);
$authMember = new SoapHeaderAuthMember('somefieldvalue');
$soapHeaders[] = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/utility', 'AuthMember', $authMember);
$client->__setSoapHeaders($soapHeaders);
$client->__soapCall('AuthenticateMember',array());
看,
1.它生成 SOAP-ENV:Envelope 而不是 SOAP-ENV:Envelope
2.in 标头:我有 ns2:AuthMember 而不是 AuthMember
3.在正文中我有 ns1:AuthenticateMember 而不是 AuthenticateMember xmlns="http://tempuri.org/"
我怎样才能得到正确的 xml ?我查看了 php 函数手册并找不到答案,谷歌搜索并没有给我的案例提供成功的结果。
能否请你帮忙 ?