我无法让我的客户协调视觉工作室添加到代理类的 AuthHeaderValue 我已经看到了很多示例,但找不到任何关于如何解决此问题的信息。
肥皂类
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);
}