Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a Soap Header with a WSDL Soap Request with PHP

I'm extremely new to SOAP and I'm trying to implement a quick test client in PHP that consumes a ASP.NET web service. The web service relies on a Soap Header that contains authorization parameters.

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

My code:

php

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

webservice

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

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

like image 552
Josh Smeaton Avatar asked Dec 30 '22 04:12

Josh Smeaton


1 Answers

You should be able to create a header and then add it to the client so it is sent for all subsequent requests. You will probably need to change the namespace parameter.

$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

More information here

like image 197
Tom Haigh Avatar answered Jan 05 '23 18:01

Tom Haigh