错误信息:An error occurred while receiving the HTTP response to http://127.0.0.1/SIHIS/Infection/PubExecuteSQL.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

跟踪堆栈信息:

Server stack trace:    at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)    at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)    at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at TabControlDemo.WCFService.IPubExecuteSQL.GetDataTableByProcedure(String procName, String[] parameterValues)    at TabControlDemo.WCFService.PubExecuteSQLClient.GetDataTableByProcedure(String procName, String[] parameterValues) in d:\练习\动态添加TabPage\TabControlDemo\TabControlDemo\Service References\WCFService\Reference.cs:line 165    at TabControlDemo.Form1.tabControl1_SelectedIndexChanged(Object sender, EventArgs e) in d:\练习\动态添加TabPage\TabControlDemo\TabControlDemo\Form1.cs:line 119

错误原因:

返回DataTable时没有TableName,导致不能序列化。

原代码:

 /// <summary>
/// 调用存储过程返回DataTable
/// </summary>
/// <param name="procName">存储过程名称</param>
/// <param name="parameterValue">存储过程参数值</param>
/// <returns></returns>
public DataTable GetDataTableByProcedure(string procName, string[] parameterValues)
{
DataTable dtReturn = new DataTable();
try
{
//连接字符串
string strConn = "";
try
{
string sFilePath = HttpRuntime.AppDomainAppPath + "..\\Connect.config";
if (System.IO.File.Exists(sFilePath))
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = sFilePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
strConn = config.ConnectionStrings.ConnectionStrings["HealthHospInfection"].ToString();
}
else
{
strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ToString();
}
}
catch (Exception ex)
{
strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ToString();
SILogUtil.Error("获取连接字符串错误:" + ex.Message + "\r\n跟踪:" + ex.StackTrace);
} SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = procName;
conn.Open(); //获取存储过程的参数
SqlCommandBuilder.DeriveParameters(cmd);
//移除存储过程参数
cmd.Parameters.RemoveAt(); //设置参数值
if (parameterValues != null)
{
for (int i = ; i < cmd.Parameters.Count; i++)
{
cmd.Parameters[i].Value = parameterValues[i];
}
} SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
//填充数据
adapter.Fill(dtReturn);
}
catch (Exception ex)
{
SILogUtil.Error("通过Proc获取数据出错:" + ex.Message + "\r\n跟踪:" + ex.StackTrace);
}
return dtReturn; }

修改之后的代码:

 /// <summary>
/// 调用存储过程返回DataTable
/// </summary>
/// <param name="procName">存储过程名称</param>
/// <param name="parameterValue">存储过程参数值</param>
/// <returns></returns>
public DataTable GetDataTableByProcedure(string procName, string[] parameterValues)
{
DataTable dtReturn = new DataTable();
//设置TableName
dtReturn.TableName = "ExecuteNoQuery";
try
{
//连接字符串
string strConn = "";
try
{
string sFilePath = HttpRuntime.AppDomainAppPath + "..\\Connect.config";
if (System.IO.File.Exists(sFilePath))
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = sFilePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
strConn = config.ConnectionStrings.ConnectionStrings["HealthHospInfection"].ToString();
}
else
{
strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ToString();
}
}
catch (Exception ex)
{
strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ToString();
SILogUtil.Error("获取连接字符串错误:" + ex.Message + "\r\n跟踪:" + ex.StackTrace);
} SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = procName;
conn.Open(); //获取存储过程的参数
SqlCommandBuilder.DeriveParameters(cmd);
//移除存储过程参数
cmd.Parameters.RemoveAt(); //设置参数值
if (parameterValues != null)
{
for (int i = ; i < cmd.Parameters.Count; i++)
{
cmd.Parameters[i].Value = parameterValues[i];
}
} SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
//填充数据
adapter.Fill(dtReturn);
}
catch (Exception ex)
{
SILogUtil.Error("通过Proc获取数据出错:" + ex.Message + "\r\n跟踪:" + ex.StackTrace);
}
return dtReturn; }

WCF客户端获取服务器返回数据报错的更多相关文章

  1. tcp程序设计--客户端获取服务器输入输出流

    tcp程序设计--客户端获取服务器输入输出流 思路: 第一步:实例化一个ServerSocket对象(服务器套接字),用来等待网络上的请求(也就是等待来连接的套接字) 第二步:调用accept()方法 ...

  2. js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可)

    js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可) 一.总结 ajax读取json和读取普通文本,和获 ...

  3. ICE学习第四步-----客户端请求服务器返回数据

    这次我们来做一个例子,流程很简单:客户端向服务器发送一条指令,服务端接收到这条指令之后,向客户端发送数据库中查询到的数据,最终显示在DataGridView上. 根据上一篇文章介绍的Slice语法,我 ...

  4. WCF客户端获取服务端异常[自定义异常]

    引言 经过不断的摸索,询问/调试,终于学会了关于WCF客户端与服务端之间异常的处理机制,在此来记录自己的成果,用于记录与分享给需要的伙伴们. 首先感谢[.NET技术群]里群主[轩]的大力帮助,如有需要 ...

  5. 客户端获取服务器SessionID (Asp.net SessionID)

    SessionID是客户端首次访问某个方法或页面, 并且这个方法中设置了Session["xxx"]=xx; 此时服务器返回的响应头(HttpResponse.Headers)中会 ...

  6. WCF客户端和服务器时间不一致,导致通道建立失败的问题)

    本文转载:http://www.cnblogs.com/bcbr/articles/2288374.html 最近,经常有客户反应,前天还用的好好的系统,今天就不能用了. 考虑到系统近来没有做过改动和 ...

  7. Java爬虫(一)利用GET和POST发送请求,获取服务器返回信息

    本人所使用软件 eclipse fiddle UC浏览器 分析请求信息 以知乎(https://www.zhihu.com)为例,模拟登陆请求,获取登陆后首页,首先就是分析请求信息. 用UC浏览器F1 ...

  8. WCF错误远程服务器返回了意外响应: (413) Request Entity Too Large。解决方案

    这个问题出现的原因是  调用wcf服务的时候传递的参数 长度太大   wcf数据传输采用的默认的大小是65535字节. ---------------------------------------- ...

  9. WCF客户端从服务器下载数据

    1.打开VS选择控制台项目新建一个解决方案Server,然后添加两个类库Contract和Service. 2.在Contract中添加一个接口IFileDownload using System; ...

随机推荐

  1. 马哥 Linux运维基础进阶和shell入门

    地址:http://edu.51cto.com/course/course_id-618.html 紧接马哥linux专题 第一讲 Bash变量: 1byte= -128,127 2bytes -32 ...

  2. 2014年15款新评定的最佳PHP框架

    通常,框架都会被认为是帮助开发者快速设计和开发动态网站的软件应用.每个月都有极大数量的新发布的 PHP 框架,使网站开发更简单更高效. 如果你是位 PHP 开发者,正在寻找当前最好的一些 PHP 框架 ...

  3. Quartz.net官方开发指南[转]

    http://www.cnblogs.com/shanyou/category/102991.html

  4. PO_已交货PO进行退货(流程)

    2014-06-04 Created By BaoXinjian

  5. WebService 闲聊

    在http://www.2cto.com/ 中搜:WebServices学习笔记(一) WebService三要素 SOAP.WSDL(WebServicesDescriptionLanguage). ...

  6. dataframe 合并(append, merge, concat)

    https://www.cnblogs.com/guxh/p/9451532.html https://blog.csdn.net/zutsoft/article/details/51498026 写 ...

  7. mysql update常见实例

    在MySQL中使用update语句的时候,Where条件或者值都可以使用子查询,比如: ) ); 但是如果子查询和更新的表是同一个表的话,MySQL会报如下的错误:中涉及到的子查询要格外注意 Erro ...

  8. Hadoop2.x介绍与源代码编译

    1.Hadoop 项目的四大模块 Hadoop Common: The common utilities that support the other Hadoop modules. Hadoop D ...

  9. 网络编程之TCP/UDP及其流程比较(转)

    TCP与UDP的区别 基于连接与无连接 对系统资源的要求(TCP较多,UDP少) UDP程序结构较简单 流模式与数据报模式TCP保证数据正确性,UDP可能丢包TCP保证数据顺序,UDP不保证 具体编程 ...

  10. Statistical Concepts and Market Returns

    Statistical Concepts and Market Returns Categories of statistics Descriptive statistics: used to sum ...