用PHP发送一个包含WSDL SOAP请求的Soap头文件

问题描述:

我对SOAP非常陌生,我试图在PHP中实现一个使用ASP.NET Web服务的快速测试客户端。 Web服务依赖于包含授权参数的Soap Header。用PHP发送一个包含WSDL SOAP请求的Soap头文件

当使用WSDL时,是否可以发送auth头文件和soap请求?

我的代码:

PHP

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

web服务

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

将如何在auth头在这种情况下通过?或者我需要做一个低杠杆__soapCall()传递头部?另外,我是否在PHP中调用正确的soap调用?

您应该能够创建一个头,然后将其添加到客户端,以便发送所有后续请求。您可能需要更改名称空间参数。

$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 

更多信息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));