我有个WCF服务没法运行下去,卡住了,请帮忙为什么
程序卡在 throw new FaultException<GetProddepinfoFault>(gpdf, new FaultReason(ex.ToString()), new FaultCode("sender"));这一句上,请问为什么?卡住的原因是:“用户代码未处理” 。我是故意把数据库服务停住,让客户端捕捉异常,结果客户端捕捉不了异常
服务端代码:
string connstring1 = @"server=192.168.0.254;integrated security=true;database=yyxt01";
string sqlquery1 = @"select prod_no,prod_add,batch_no,lest_num,box_num,avail_Date,'yyxt01' as belong_to from prod_dep";
SqlConnection conn1 = null;
SqlDataReader reader1 = null;
MyProddepDataContract myPorddepDataContract = new MyProddepDataContract();
int i = 0;
try
{
conn1 = new SqlConnection(connstring1);
conn1.Open();
SqlCommand cmd1 = new SqlCommand(sqlquery1, conn1);
reader1 = cmd1.ExecuteReader();
while (reader1.Read())
{
myPorddepDataContract.Myprodno[i] = reader1[0].ToString();
myPorddepDataContract.Myprodadd[i] = reader1[1].ToString();
myPorddepDataContract.Mybatchno[i] = reader1[2].ToString();
myPorddepDataContract.Mylestnum[i] = Convert.ToDecimal(reader1[3]);
myPorddepDataContract.Myboxnum[i] = reader1[4].ToString();
myPorddepDataContract.Myavaildate[i] = Convert.ToDateTime(reader1[5]);
myPorddepDataContract.Mybelognto[i] = reader1[6].ToString();
i++;
}
}
catch (Exception ex)
{
GetProddepinfoFault gpdf = new GetProddepinfoFault();
gpdf.Operation = "GetProddepinfo在对数据库yyxt01处理时发生异常";
gpdf.ProblemType = ex.ToString();
throw new FaultException<GetProddepinfoFault>(gpdf, new FaultReason(ex.ToString()), new FaultCode("sender"));
}
finally
{
reader1.Close();
conn1.Close();
}
[解决办法]
你在看看FaultException<T>的介绍,对应Service的Contract上面可以设定属性说明T可以是哪些内容,这样才可以给客户端用呢。
[解决办法]