简体   繁体   中英

How to pass authentication header for WSDL XML with PHP soap?

I have the following auth header to be passed from php soap client

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

</soap:Header> How can I pass this in PHP soap header?. In the WSDL file I have it like

 <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>

I would also like to know how can I call the function StartFixedLineTest after passing the authentication header. Please help

You should be able to make the SOAP call with the following code (maybe you need some extra 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM