错误信息: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. JS阻止冒泡方法(转)

    S事件流其中一种是冒泡事件,当一个元素被触发一个事件时,该目标元素的事件会优先被执行,然后向外传播到每个祖先元素,恰如水里的一个泡泡似的,从产生就一直往上浮,到在水平面时,它才消失.在这个过程中,如果 ...

  2. 【php】基础学习1

    其中包括php基础.字符串和正则表达式的学习.具体如下: <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta h ...

  3. C# 默认参数/可选参数需要注意

    在使用C#的默认参数/可选参数的时候,需要注意,参数的默认值是在编译的时候,自动加入调用方的. 如我有这样一个方法: public class Name { public void Test(Bool ...

  4. XtraTreeList直接显示Access数据库表中的数据

    方法1:点击在拖入的显示控件(TreeList)右上方的箭头,在Treelist任务中选择数据源,添加项目数据源,依次选择数据库.数据集,新建连接,浏览选择数据库(*.mdb),依次点击 下一步,选择 ...

  5. 进程间通信机制(管道、信号、共享内存/信号量/消息队列)、线程间通信机制(互斥锁、条件变量、posix匿名信号量)

    注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料如<linux内核完全剖析>.<linux c 编程一站式学习>等,只是为了更好 ...

  6. python解压压缩包的几种方法

    这里讨论使用Python解压例如以下五种压缩文件: .gz .tar  .tgz .zip .rar 简单介绍 gz: 即gzip.通常仅仅能压缩一个文件.与tar结合起来就能够实现先打包,再压缩. ...

  7. VirtualBOX 不能mount优盘,移动硬盘解决方案

    The Solution (basically nayasis' solution with the second driver installation added): Safely unplug ...

  8. 深入浅出Node.js--数据通讯,NET模块运行机制

    互联网的运作,最根本的驱动就是信息的交互,NodeJS 在数据交互这一块做的很带感,异步编程让人很惬意,关于 NodeJS 的数据通信,最基础的两个模块是 NET 和 HTTP,前者是基于 TCP 的 ...

  9. 在ModelSim中添加Xilinx仿真库

    在ModelSim中添加Xilinx仿真库 说明: l ModelSim一定要安装在不带空格的目录下,即不要安装在“Program Files”目录下.如作者是安装在D:\softwares\Mode ...

  10. ssh 连 koding

    2014.12.10更新可用方法 koding是一个在线的开发平台.让自己从开发平台中释放出来.除了提供在线编程功能之外,Koding还有强大的社区功能,允许开发者通过相互浏览.交换代码而达到项目协作 ...