使用 PHP 发送带有 WSDL Soap 请求的 Soap 标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/589228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending a Soap Header with a WSDL Soap Request with PHP
提问by Josh Smeaton
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.
我对 SOAP 非常陌生,我正在尝试在 PHP 中实现一个使用 ASP.NET Web 服务的快速测试客户端。Web 服务依赖于包含授权参数的 Soap Header。
Is it possible to send the auth header along with a soap request when using WSDL?
使用 WSDL 时是否可以将 auth 标头与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? 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?
在这种情况下如何传递 auth 标头?或者我需要做一个低杠杆 __soapCall() 来传递标题吗?另外,我是否在 PHP 中调用了正确的肥皂调用?
回答by Tom Haigh
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
更多信息在这里
回答by cjjer
$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));

