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

kke_007 2009-07-27 05:37:45
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");
}

...全文
4301 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
bin410384195 2012-05-02
  • 打赏
  • 举报
回复
事隔多年 我看看对有没有帮助
jackeyabc 2010-05-24
  • 打赏
  • 举报
回复
asdfsdfsadfsadf
jzj083271930 2010-04-20
  • 打赏
  • 举报
回复
怎么没有正确答案呢?我也在等啊!
吕津 2009-07-30
  • 打赏
  • 举报
回复
帮顶
gongsun 2009-07-29
  • 打赏
  • 举报
回复
DataRow dr= LuhooLogin(username, pwd);


这个东西,看看 dr 有没有附上值。
zhouzangood 2009-07-29
  • 打赏
  • 举报
回复
关注下
kke_007 2009-07-29
  • 打赏
  • 举报
回复
不行
wuyq11 2009-07-27
  • 打赏
  • 举报
回复
有对象为null值,添加try catch判断
wuyq11 2009-07-27
  • 打赏
  • 举报
回复
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中字段是否正确
  • 打赏
  • 举报
回复
你这webservice 断点是不会进这里面的来。
kke_007 2009-07-27
  • 打赏
  • 举报
回复
好像跟本就不会调用
  • 打赏
  • 举报
回复
请检查你这里面
/// <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

62,040

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧