我不能讓我的客戶reconise AuthHeaderValue其視覺工作室添加到我見過很多例子,但能找到如何解決這個沒什麼代理類 。SOAPHEADER認證
皁類
public class AuthHeader : SoapHeader
{
public string Username;
public string Password;
}
Web服務
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);
}
固定它來驗證服務。添加服務引用而不是Web引用。 DUU –