【问题标题】:How to define a SoapVar namespace?如何定义 SoapVar 命名空间?
【发布时间】:2012-06-06 13:49:40
【问题描述】:

我需要在我的 SOAP 请求中包含这个节点(使用 1.1):

<CredentialsHeader xmlns="http://www.url.com/Services/P24ListingService11"
    <EMail>ricky@email.net</EMail>
    <Password>password</Password>
</CredentialsHeader>

所以我有以下 PHP:

$client = new SoapClient("https://exdev.www.example.com/Services/example.asmx?WSDL", 
    array(
        "trace"      => 1,
        "exceptions" => 0,
        "cache_wsdl" => 0,
        'soap_version' => SOAP_1_1
        )
);

$CredentialObject = new SoapVar(array('EMail' => 'ricky@email.net', 'Password' => 'password'), SOAP_ENC_OBJECT);

生成:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Services/Example">
    <SOAP-ENV:Header>
        <ns1:CredentialsHeader>
            <EMail>ricky@email.net</EMail>
            <Password>password</Password>
        </ns1:CredentialsHeader>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:EchoAuthenticated/>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我需要做的就是使用ns1 阻止它,并像这样在节点中实际定义xmlns

<CredentialsHeader xmlns="http://www.example.com/Services/Example">
        <EMail>ricky@email.net</EMail>
        <Password>password</Password>
    </CredentialsHeader>

我已经在 Firefox Poster 中对此进行了测试,并且知道更改可以解决问题。

【问题讨论】:

    标签: php soap namespaces soap-client


    【解决方案1】:

    http://www.php.net/manual/tr/soapvar.soapvar.php

    我猜参数“node_namespace”是你一直在寻找的。​​p>

    【讨论】:

    • 你能写一个例子吗?我一直在尝试使该参数适用于我的示例,但不能!
    【解决方案2】:
    $CredentialObjectXML  = '<CredentialsHeader xmlns="http://www.example.com/Services/Example">
            <EMail>'.$UserName.'</EMail>
            <Password>'.$Password.'</Password>
        </CredentialsHeader>';
    
    
    $CredentialObject  = new SoapVar($CredentialObjectXML,XSD_ANYXML);
    

    这样你可以直接使用 XSD_ANYXML 类型的 XML。

    希望这能解决您的问题。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,发现如果你从 WSDL 将一个虚拟类映射到凭据复杂类型,PHP 将输出如下内容:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Services/Example">
          <SOAP-ENV:Header>
              <ns1:CredentialsHeader>
                  <ns1:EMail>ricky@email.net</ns1:EMail>
                  <ns1:Password>password</ns1:Password>
              </ns1:CredentialsHeader>
          </SOAP-ENV:Header>
          <SOAP-ENV:Body>
              <ns1:EchoAuthenticated/>
          </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      

      这不是所要求的,但虽然更详细,但它是等效的。

      代码如下:

      $client = new SoapClient("https://exdev.www.example.com/Services/example.asmx?WSDL", 
          array(
              "trace"         => 1,
              "exceptions"    => 0,
              "cache_wsdl"    => 0,
              "soap_version"  => SOAP_1_1,
              "classmap"      => array(
                  'credential_complex_type'   => 'CredentialObject',
              ),
          )
      );
      
      class CredentialObject {}
      
      $credentialObject = new CredentialObject();
      $credentialObject->Email = 'ricky@email.net';
      $credentialObject->Password = 'password';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-23
        • 2013-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多