关键字 : ASP.NET mode="Forms" Web Service
项目种遇到这么个问题,在用Form认证的ASP.NET程序内调用同一虚拟目录下的web service,这样也需要有认证信息,网上找了很久没结果,都说Form认证不适合webservice,但是我就需要嗒~~,后来仔细想了想,form认证就是用cookie来传递的,于是测试了以下代码,搞定~~
AsyncCallback acb = new AsyncCallback(类名.UpdateDoneCallback);
UpdateServiceProxy proxy = new UpdateServiceProxy();
//Attach Cookie to confirm current user
proxy.CookieContainer = new System.Net.CookieContainer();
for(int i=0;i<this.Request.Cookies.Count;i++)
{
proxy.CookieContainer.Add(new Uri(proxy.Url),new System.Net.Cookie(this.Request.Cookies[i].Name,
this.Request.Cookies[i].Value));
}
//调用Service 方法
proxy.BeginUpdateEx(。。。);