public class MyHeader : SoapHeader
{
public string Username;
public string Password;
}
[WebService(Namespace = "http://tempuri.org/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
public WebService ()
{
}
//AD 验证用户
public bool validateUser(string userName, string passWord)
{
bool userBool;
string un = userName;
string pw = passWord;
if (true)
{
HttpCookie cookie = new HttpCookie( ".BarAuth ");
cookie.Value = un;
cookie.Expires = DateTime.Now.AddHours(1);
HttpContext.Current.Response.Cookies.Add(cookie);
userBool = true;
}
else
{
userBool = false;
}
return userBool;
}
//ADUser
public MyHeader my;
[WebMethod]
[SoapHeader( "my ", Direction = SoapHeaderDirection.Out)]
public void ADUser()
{
my = new MyHeader();
if (HttpContext.Current.Request.Cookies[ ".BarAuth "].Value != null)
{
my.Username = HttpContext.Current.Request.Cookies[ ".BarAuth "].Value;
}
}
}
在调用ADUser()出现如下错误:
System.Web.Services.Protocols.SoapException: 服务器无法处理请求
我测试过了,只要吧HttpContext.Current.Request.Cookies[ ".BarAuth "].Value;