首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 特急该如何解决

2012-05-03 
System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 特急System.Web.Services.Protocols.

System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 特急
System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。
  在 Service.Login(String username, String pwd)
  --- 内部异常堆栈跟踪的结尾 --- 

  using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
  public Service () {

  //如果使用设计的组件,请取消注释以下行 
  //InitializeComponent(); 
  }

  [WebMethod]
  public int Login(string username,string pwd)
  {
  DataRow dr= LuhooLogin(username, pwd);
  if (dr != null)
  {
  Session.Add("l_Name", dr["Id"].ToString());
  Session.Add("l_id", dr["UserName"].ToString());
  return 1;
  }
  else {
  return 0;
  }
  }

  private DataRow LuhooLogin(string name, string pwd) {
  pwd = MD5(pwd, true);
  string sql = string.Format("select * from xys_sys_User where UserName='{0}' and UserPassword ='{1}'",name,pwd);
  DataSet ds= FillDS(sql);
  if (ds == null) {
  return null;
  }
  if (ds.Tables[0].Rows.Count > 0)
  {
  return ds.Tables[0].Rows[0];
  }
  else {
  return null;
  }
  }


  private string MD5(string Input, bool Half)
  {
  string output = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Input, "MD5").ToLower();
  if (Half)//16位MD5加密(取32位加密的9~25字符)
  output = output.Substring(8, 16);
  return output;
  }

  private SqlConnection getConn()
  {
  try
  {
  String connString;
  connString = "server=.;uid=xys;pwd=xuey;database=XYSCMS;";
  SqlConnection myConnection1 = new SqlConnection(connString);
  return myConnection1;
  }
  catch (Exception e)
  {
  // Display the error. 
  return null;
  Console.WriteLine(e.ToString());
  }
  }

  /// <summary>
  /// 查询
  /// </summary>
  /// <param name="sql"></param>
  /// <returns>datase</returns>
  private DataSet FillDS(string sql)
  {
  SqlConnection conn = getConn();
  try
  {
  DataSet ds = new DataSet();
  SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
  ad.Fill(ds);
  return ds;
  }
  catch
  {

  }
  finally
  {
  conn.Close();
  }
  return null;
  }
   
}


调用

 Service FlashNetLogin = new Service();
  int i = FlashNetLogin.Login("kke_007", "646516");


  if (i == 0)
  {
  Response.Write("失败");
  }
  else
  {
  Response.Redirect("http://192.168.0.2:8080/first.aspx");
  }



[解决办法]
请检查你这里面
 /// <summary> 
/// 查询 
/// </summary> 
/// <param name="sql"> </param> 
/// <returns>datase </returns> 
private DataSet FillDS(string sql) 

SqlConnection conn = getConn(); 
try 

DataSet ds = new DataSet(); 
SqlDataAdapter ad = new SqlDataAdapter(sql, conn); 
ad.Fill(ds); 
return ds; 

catch 



finally 

conn.Close(); 

return null; 




是否返回了dataset
[解决办法]
你这webservice 断点是不会进这里面的来。
[解决办法]
LuhooLogin函数执行问题
SqlConnection sqlConnection1 = new SqlConnection("");
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM table1",sqlConnection1); sqlConnection1.Open();
SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(sqlCmd);
 DataSet result =new DataSet();
 sqlDataAdapter1.Fill(result);
 sqlConnection1.Close();


DataRow dr中字段是否正确
[解决办法]
有对象为null值,添加try catch判断
[解决办法]
关注下
[解决办法]
DataRow dr= LuhooLogin(username, pwd); 
 

这个东西,看看 dr 有没有附上值。
[解决办法]
帮顶

热点排行