无法通过 PHP 生成正确的 SOAP XML 请求


cannot generate proper soap xml request via php

我正在尝试创建适当的基于 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>

我的结果是:肥皂.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());

see,

1.it generates SOAP-ENV:Envelope instead of SOAP-ENV:Envelope

2.in header: I have ns2:AuthMember instead of AuthMember

3.in body I have ns1:AuthenticateMember instead of AuthenticateMember xmlns="http://tempuri.org/"

How can I get proper xml ? I've looked through php functions manuals and cannot find the answer, googling did not give me success results for my case.

Could you please help ?

The result that has been generated is what has been requested in the code, but an explanation of some attributes of namespaces is in order:

Each of the tags in an XML document has a fully-qualified form which is defined by the namespace and the tag name (even if it is in the 'default' namespace with no explicit namespace declaration). The fully-qualified version is typically written as {namespace}tag. By resolving the fully-qualified name it is possible to determine whether the representation of two elements is the same.

Namespaces are associated with elements in multiple ways including explicit namespace inclusion with the element

Example:
<AuthMember xmlns="http://tempuri.org/">
resolving to fully-qualified name {http://tempuri.org/}AuthMember

以及通过命名空间关联的前缀

Example:
<... xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
resolving to {http://schemas.xmlsoap.org/soap/envelope/}Header
前缀

位于声明前缀的元素和任何包含的元素的范围内。 实际使用的前缀并不重要(soapSOAP-ENVrandomprefix 可用于 http://schemas.xmlsoap.org/soap/envelope/ 命名空间(,尽管好的做法是使用有意义的东西。

鉴于此,"所需"和"实际"文档中的完全限定元素几乎相同,异常是标头元素 AuthMember。在所需的中,为完全限定的 {http://tempuri.org/}AuthMember 指示 http://tempuri.org/ 命名空间。在实际中,前缀关联会产生完全限定的 {http://schemas.xmlsoap.org/ws/2002/07/utility}AuthMember

这是 SoapHeader 实例化指定 ...身份验证成员的实用程序命名空间。 将代码中的该语句更改为使用 http://tempuri.org/ 命名空间应导致实际文档与所需匹配。