关于webservice,急!!!! 在线等
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;
去掉就可以了,反回其它的直没有错!
[解决办法]
代码太长,懒得看了。
改成HttpContext.Current.Response.Cookies试试。
[解决办法]
如果是winform调用webservice,这时websercie的session和cookie状态是不会保存的,调用方法结束session和cookie就失效了。如果是webform调用是可以的