错误信息: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. Java程序作linux服务并且开机自动启动[转]

    以有个java应用名称为test,打包为test.jar,程序入口为cn.com.ppnote.SocketServer. 下面在linux的/opt下建立testapp目录,复制test.jar到/ ...

  2. Jquery与mootools对比

    换了新公司以后就很少使用原生Js来实现界面交互了,而是更多的依赖Jquery. 1.Jquery优点: 良好的一致性$().().xxxxx与强大的DOM api组件可以让一个js菜鸟一周之类立马开发 ...

  3. SSAS 笔记

    SQL SERVER 2000创建多维数据集对应的cub文件   http://blog.csdn.net/zklth/article/details/6367816     http://msdn. ...

  4. WordPress For SAE进入后台

    今天遇到一个非常easy可是花了我半个小时的问题:怎样进入WordPress For SAE后台. 介于百度上没有搜索到.所以写了这篇博客,简单,but有用. 首先我们会訪问自己的网站:独立游戏者er ...

  5. python 中 with 用法

    前言 with 语句适用于对资源进行访问的场合,确保不管使用过程中是否发生异常都会执行必要的“清理”操作,释放资源, 比如文件使用后自动关闭/线程中锁的自动获取和释放等. 问题引出 如下代码: fil ...

  6. caffe make 编译

    其实嘛,出现这个的原因在于,已经编译过啦,没有任何改动,那还烦劳编译啥呢. 那Linux又是如何知道已经编译过了呢? 那就要看makefile的规则啦.makefile的规则是所想产生的文件需要依赖很 ...

  7. 在windows下部署Redis 当作系统服务器自动启动

    部署Redis 其实Redis是可以安装成windows服务的,开机自启动,命令如下: redis-server --service-install redis.windows.conf 安装完之后, ...

  8. jquery的animate()方法也可设置非css属性

    如题,举例: $('body').animate({scrollTop:0}, 1500); $("body").animate({scrollTop:"-=" ...

  9. struts中action名称反复导致的神秘事件

    近期由于项目需求变更.须要本人对当中的某个业务功能进行改动.本人依照前台页面找action,依据action找代码的逻辑进行了改动(公司项目是ssh框架,struts配置全部是通过注解的方式进行.配置 ...

  10. Server Process

    1.client进行update操作后.其它是怎么协作的? Client进行update操作之后,是由Server Process真正完毕的,分以下几步: 1).须要更新的数据在Data buffer ...