简体   繁体   中英

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?

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

$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));

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