Webservice中异常处理记录---(out DataTable Output_table, out string resultMessage)
[WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void Station_Manage(string strJson, out DataTable Output_table, out string resultMessage) { Output_table = new DataTable("ChildSNList"); string strguid = string.Empty; try { strguid = Guid.NewGuid().ToString(); resultMessage = "OK"; string strSqlResult = string.Empty; DataTable dtResult = new DataTable(); DataTable input_table = JsonConvert.DeserializeObject<DataTable>(strJson); //--先获取测试Table,然后循环出入临时表,然后传入对应的参数信息--// if (input_table.Rows.Count > 0) { #region sql excute if (input_table != null) { { for (int ix = 0; ix < input_table.Rows.Count; ix++) { string strSQL = "Insert Into sfcruntime.R_CHECKSN_IN_OUT ( GUIDNO,MSERIALNUMBER)"; OracleParameter[] deleteOp = new OracleParameter[] { new OracleParameter("GUIDNO", strguid), new OracleParameter("MSERIALNUMBER", input_table.Rows[ix]["serialnumber"].ToString().Trim()) }; MES.Lib.DBHelper.OracleHelper.ExecuteNonQuery(OracleConnectString, CommandType.Text, strSQL, deleteOp); } } } #endregion //--调用存储过程返回处理结果--// string[] oracleParams = { strguid.Trim(), "", "" }; ExecuteSP.ExecuteSPReturnOneStringAndOneDataTable(OracleConnectString, "ap.pkg_mes_auto_ft_inf.main", "last", ref strSqlResult, ref dtResult, oracleParams);
//必须要加验证dtResult是否有数据;
//如果直接通过Copy()给Output_table,异常现象----客户端调用时会导致另一个out参数 resultMessage始终返回null; if (dtResult != null && dtResult.Rows.Count > 0) { Output_table = dtResult.Copy(); Output_table.TableName = "Output_table"; }else { Output_table = null; } resultMessage = strSqlResult; AddLog("MachineParamsOperation", "Station_Manage", "machineName:" + strguid + " ,resultMessage:" + strSqlResult + " ; 请求结果:" + strSqlResult + strJson, "当前的方法:Station_Manage", "相关SP:AP.pkg_mes_auto_ft_inf.main", "LOG类型:记录请求", "", "", "", "", "", GetClientIP()); } else { resultMessage = "传入参数错误!"; } } catch (Exception ex) { resultMessage = ex.ToString(); AddLog("MachineParamsOperation", "Station_Manage", "machineName:" + strguid + " ,resultMessage:" + resultMessage + " ; 异常:" + ex.Message + strJson, "当前的方法:Station_Manage", "相关SP:AP.pkg_mes_auto_ft_inf.main", "LOG类型:异常", "", "", "", "", "", GetClientIP()); } }