.NET WSE 3.0的替代品

时间:2010-09-10 08:11:40

标签: web-services soap header

我正在使用.NET 2.0。 .NET WSE 3.0有什么替代方案吗?

是否可以在没有任何工具包的情况下在soap标头中传递用户名和密码,只使​​用代码?

由于

2 个答案:

答案 0 :(得分:1)

(这个建议可能有点偏,因为我不确定你是指一些特殊的WS。*标题,还是只是任何自定义标题......我从未听说过WSE)

我在标题中使用user / pass调用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();

网络服务:

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;
}

答案 1 :(得分:0)

可以使用 SOAP扩展更改SOAP消息,包括所需的 SOAP标头