http://ourstrade.blog.163.com/blog/static/123663391201072411444580/

解决方案 »

  1.   

    调用WebService时加入身份验证,拒绝未授权的访问 //Session方式验证做起来比较容易:调用之前用string _GetValue 验证下。
    [WebMethod(Description = "检测是否正确登录", EnableSession = true)]              
    public bool CheckLogin(string strUserName, string strPassword)                   
    {                                                                                
    if (strUserName.Equals("admin") && strPassword.Equals("123456"))                 
    {                                                                                
    Session["LoginState"] = true;                                                    
    }                                                                                
    else                                                                             
    {                                                                                
    Session["LoginState"] = false;                                                 
    }                                                                              
    return (bool)Session["LoginState"];                                            
    }         
    //调用时候,现在数据库验证一下用户、和密码是否正确[WebMethod(Description = "测试连接", EnableSession = true)]                      
    public string _GetValue(string strInputValue)                                    
    {                                                                                
        if (Session["LoginState"] == null || Session["LoginState"].Equals(false))    
        {                                                                            
            return "无效的身份验证,请重试!";                                       
        }                                                                            
        else                                                                         
        {                                                                            
            string strReturnValue = strInputValue + "@CopyRight By BanLao 2010";     
            return strReturnValue;                                                   
        }                                                                            
    }  调用该服务,                                                                                             
                                                                                                             
                                                                                                                                                                                WebLogon.Service This_Service = new WebLogon.Service();                                                  
    This_Service.CookieContainer = new System.Net.CookieContainer();                                         
    if (This_Service.CheckLogin("admin", "123456"))                                                          
    {                                                                                                        
    Response.Write(This_Service._GetValue("This is BanLao's Test Application For Session. "));    
    }       
                                                                                       
      

  2.   

    不用用户密码也可以,给客户一个Guid,总归要知道是谁调用的方法的
      

  3.   

    用户名和密码其实很方便,每次也只是初始化调用的时候要验证一下,后面都存在session里面