简体   繁体   English

Sending a Soap Header with a WSDL Soap Request with PHP

[英]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.我对 SOAP 非常陌生,我正在尝试在 PHP 中实现一个快速测试客户端,该客户端使用 ASP.NET617867A48EC937CE05 服务。 The web service relies on a Soap Header that contains authorization parameters. web 服务依赖于包含授权参数的 Soap Header。

Is it possible to send the auth header along with a soap request when using WSDL?使用 WSDL 时,是否可以发送身份验证 header 以及 soap 请求?

My code:我的代码:

php 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?在这种情况下如何传递 auth header ? Or will I need to do a low lever __soapCall() to pass in the header?或者我需要做一个低杠杆__soapCall()来传递header? Also, am I invoking the correct soap call within PHP?另外,我是否在 PHP 中调用了正确的 soap 调用?

You should be able to create a header and then add it to the client so it is sent for all subsequent requests.您应该能够创建 header,然后将其添加到客户端,以便为所有后续请求发送它。 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM