大家都知道,Ajax调用Web Service方法的技巧(其他书上也有介绍),可现实中,为了保证Web service的安全性,都需要添加SoapHeader来进行验证,那么如果要用javascript来进行验证,可我怎么搞的都调不通,请教各位高手!!!基本程序介绍如下:
Web service:[GenerateScriptType(typeof(UserInfo))]
[scriptService]
public CustomersService
{
     private UserInfo userinfo;
     public UserInfo User
     {
          get{return userinfo;}
          set{userinfo=value;}
     }
     [WebMethod][SoapHeader("User")]
     public DataTable GetCustomers(string from,string to)
     {
          .........
     }
     public bool Verify()
     {
          Check userinfo
     }
}[GenerateScriptType(typeof(UserInfo))]
[ScriptService]
public class UserInfo
{
   private string userid;
   private string password;
   public string UserID
   {
      get{return userid;}
      set{userid=value;}
   }
   public string Password
   {
      get{return password;}
      set{password=value;}
   }
}Ajax调用
function cmdSearch_click() {
                var cfrom=$get("txtFrom").value;
                var cto = $get("txtTo").value;
                var user = new UserInfo("admin", "admin");
                CustomerServices.User=user;//(注意:此处通过[GenerateScriptType(typeof(UserInfo))]产生的脚本类无这个属性,不知道什么原因)                
CustomerServices.GetCustomers(cfrom, cto, onCustomersSuccessed, onCustomersFailed);
            }            function onCustomersSuccessed(result) {
                alert("Successed");
            }
            function onCustomersFailed(error) {
                alert("Failed");
            }
同时也用过set_defaultUserContext属性,可还是不行,如果要这样我该怎么调用????????? 

解决方案 »

  1.   

    http://www.xue5.com/itedu/200802/108698.html
      

  2.   

    //CustomerServices.User=user;不可以这样做,因为很明显
    public CustomersService 

        private UserInfo userinfo; 
        public UserInfo User 
    ...
    从上面都可以看到,你的User属性不会公开到客户端,你不如
    [WebMethod][SoapHeader("User")] 
        public DataTable GetCustomers(string from,string to, UserInfo user