我无法让我的客户重新调整 Visual Studio 添加到代理类的 AuthHeaderValue 我看过很多例子,但找不到任何关于如何解决这个问题的方法。
SOAP 类
public class AuthHeader : SoapHeader
{
public string Username;
public string Password;
}
网络服务
public class Service1 : System.Web.Services.WebService
{
public AuthHeader Authentication; ** where does visual studio append value to proxy
[SoapHeader("Authentication", Required = true)]
[WebMethod]
public string security()
{
if (Authentication.Username == "test" &&
Authentication.Password == "test")
{
return "authenticated";
}
else
{
return "get lost";
}
}
客户
static void Main(string[] args)
{
ServiceReference1.AuthHeader auth = new ServiceReference1.AuthHeader();
auth.Username = "test";
auth.Password = "test";
ServiceReference1.Service1SoapClient ser = new ServiceReference1.Service1SoapClient();
ser.AuthHeaderValue = auth; ** does not reconise authheadervalue
String message = ser.security();
Console.WriteLine(message);
}
最佳答案
您必须将身份验证参数值作为 header 的 TRUE
传递。
查看完整解决方案 here
关于c# - soapheader认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12158545/