我正在使用.NET 2.0。除了.NET WSE3.0,还有其他的选择吗?
是否可以在soap头中传递用户名和密码,而不需要任何工具包,只需使用代码?
谢谢
发布于 2010-09-10 08:37:51
(这个建议可能很离谱,因为我不确定您是指某些特殊的WS.*标题,还是任何自定义的标题.我从未听说过WSE)
我按如下方式调用具有用户/传递头的webservice。这不是生产代码,但是代码段应该说明这一点。
客户机上的:
string userName = "someusername";
string password = "somepass";
//create the custom header object
MyService.AuthHeader authHeader = new MyService.AuthHeader();
authHeader.UserName = userName;
authHeader.Password = password;
//create the WS-proxy
MyService.SomeWebservice someWS = new MyService.SomeWebservice();
//set headers
someWS.AuthHeaderValue = authHeader;
someWS.SomeMethod();webservice:
public class SomeWebservice : System.Web.Services.WebService
{
public AuthHeader Authentication = null; //For receiving the authentication header from the SOAP client (you will never assign this property in user code, .NET handles the plumbing based on the [SoapHeader("Authentication")] attribute
[WebMethod(Description = "Some webservice method")]
[SoapHeader("Authentication")]
public void SomeMethod()
{
string suppliedUserName = Authentication.UserName;
string suppliedPassword = Authentication.Password;
}
}AuthHeader类:(定义在"WS端“)
public class AuthHeader : SoapHeader
{
public string UserName = null;
public string Password = null;
}发布于 2010-09-10 11:17:50
可以使用SOAP扩展(包括所需的SOAP头)更改SOAP消息
https://stackoverflow.com/questions/3683094
复制相似问题