【问题标题】:How to pass authentication header for WSDL XML with PHP soap?如何使用 PHP soap 传递 WSDL XML 的身份验证标头?
【发布时间】:2021-08-25 10:17:29
【问题描述】:

我有以下 auth 标头要从 php soap 客户端传递

<soap:Header>
 <AuthNASoapHeader   xmlns="http://example.com/Wholesale">
  <ClientName>string</ClientName>
  <Password>string</Password>
</AuthNASoapHeader>

标题> 我怎样才能在 PHP 肥皂头中传递这个?在 WSDL 文件中,我喜欢它

 <s:element name="AuthNASoapHeader" type="tns:AuthNASoapHeader" />
  <s:complexType name="AuthNASoapHeader">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="ClientName" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
    </s:sequence>
    <s:anyAttribute />
  </s:complexType>
  <s:element name="StartFixedLineTest">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="circuitNumber" type="s:string" />
      </s:sequence>
    </s:complexType>
  </s:element>

我也想知道如何在通过身份验证标头后调用函数 StartFixedLineTest。请帮忙

【问题讨论】:

    标签: php xml api soap wsdl


    【解决方案1】:

    您应该能够使用以下代码进行 SOAP 调用(也许您需要一些额外的 Soapoptions)

    <?php  
    
    $auth = (object)[
    'user' => 'username',
    'password' => 'password'];
    
    $authHeader = new SoapHeader('namespace','AuthNASoapHeader', $auth);
    
    $soapClient = new SoapClient('http://localhost:44333/SoapService.com?wsdl');
    $soapClient->__setSoapHeaders($authHeader);
    
    $return = $soapClient->__soapCall('StartFixedLineTest',[
        'parameters' => [
            'circuitNumber' => 'SomeNumber'
        ]
    ]);
    var_dump($return);
    

    【讨论】:

    • 谢谢。我们应该提供什么作为$authHeader = new SoapHeader('namespace','AuthNASoapHeader', $auth);中的命名空间@
    • example.com/Wholesale 是您定义的命名空间。
    猜你喜欢
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2018-06-11
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多