Sending Soap header using WSDL Soap Request with PHP

I am very new to SOAP and I am trying to implement a fast PHP test client that uses the ASP.NET web service. The web service is based on the Soap header, which contains the authorization parameters.

Is it possible to send an auth header along with a soap request when using WSDL?

My code is:

Php

$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
$service->AddPendingUsers($users, 3); // Example

web service

[SoapHeader("AuthorisationHeader")]
[WebMethod]
public void AddPendingUsers(List<PendingUser> users, int templateUserId)
{
    ateamService.AddPendingUsers(users, templateUserId, AuthorisationHeader.UserId);
}

How will the auth header be passed in this context? Or do I need to make a low __soapCall () lever to pass in the header? Also, am I calling the correct soap call in PHP?

+3
source share
2 answers

, , . , , .

$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
//                        Namespace               Header Name          value   must-understand
$header = new SoapHeader('http://tempuri.org/', 'AuthorisationHeader', $value, false);
$service->__setSoapHeaders(array($header));   

$service->AddPendingUsers($users, 3); // Example

+6
$client = new SoapClient(PassportWebService);
$apiauth =array('userName'=>HeaderName,'password'=>HeaderPassport,'ip'=>$onlineip);

$authvalues = new SoapVar($apiauth, SOAP_ENC_OBJECT,'ReqHeader',"SoapBaseNameSpace");
$header =  new SoapHeader("SoapBaseNameSpace","ReqHeader", $authvalues, true);
$client->__setSoapHeaders(array($header));
+3

Source: https://habr.com/ru/post/1703868/


All Articles