Sending a Soap Header with a WSDL Soap Request with PHP

醉酒当歌 提交于 2019-12-21 05:17:10

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/589228/sending-a-soap-header-with-a-wsdl-soap-request-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!