WCF客户端获取服务器返回数据报错
错误信息: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客户端获取服务器返回数据报错的更多相关文章
- tcp程序设计--客户端获取服务器输入输出流
tcp程序设计--客户端获取服务器输入输出流 思路: 第一步:实例化一个ServerSocket对象(服务器套接字),用来等待网络上的请求(也就是等待来连接的套接字) 第二步:调用accept()方法 ...
- js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可)
js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可) 一.总结 ajax读取json和读取普通文本,和获 ...
- ICE学习第四步-----客户端请求服务器返回数据
这次我们来做一个例子,流程很简单:客户端向服务器发送一条指令,服务端接收到这条指令之后,向客户端发送数据库中查询到的数据,最终显示在DataGridView上. 根据上一篇文章介绍的Slice语法,我 ...
- WCF客户端获取服务端异常[自定义异常]
引言 经过不断的摸索,询问/调试,终于学会了关于WCF客户端与服务端之间异常的处理机制,在此来记录自己的成果,用于记录与分享给需要的伙伴们. 首先感谢[.NET技术群]里群主[轩]的大力帮助,如有需要 ...
- 客户端获取服务器SessionID (Asp.net SessionID)
SessionID是客户端首次访问某个方法或页面, 并且这个方法中设置了Session["xxx"]=xx; 此时服务器返回的响应头(HttpResponse.Headers)中会 ...
- WCF客户端和服务器时间不一致,导致通道建立失败的问题)
本文转载:http://www.cnblogs.com/bcbr/articles/2288374.html 最近,经常有客户反应,前天还用的好好的系统,今天就不能用了. 考虑到系统近来没有做过改动和 ...
- Java爬虫(一)利用GET和POST发送请求,获取服务器返回信息
本人所使用软件 eclipse fiddle UC浏览器 分析请求信息 以知乎(https://www.zhihu.com)为例,模拟登陆请求,获取登陆后首页,首先就是分析请求信息. 用UC浏览器F1 ...
- WCF错误远程服务器返回了意外响应: (413) Request Entity Too Large。解决方案
这个问题出现的原因是 调用wcf服务的时候传递的参数 长度太大 wcf数据传输采用的默认的大小是65535字节. ---------------------------------------- ...
- WCF客户端从服务器下载数据
1.打开VS选择控制台项目新建一个解决方案Server,然后添加两个类库Contract和Service. 2.在Contract中添加一个接口IFileDownload using System; ...
随机推荐
- Android学习系列(3)--App自动更新之自定义进度视图和内部存储
友好的视觉感知和稳定的不出错表现,来自于我们追求美感和考虑的全面性,博客园从技术的角度,一直我都很欣赏.这篇文章是android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. 这 ...
- 如何理解并学习javascript中的面向对象(OOP) [转]
如果你想让你的javascript代码变得更加优美,性能更加卓越.或者,你想像jQuery的作者一样,写出属于自己优秀的类库(哪怕是基于 jquery的插件).那么,你请务必要学习javascript ...
- JVM性能监控
有时候我们会碰到下面这些问题: OutOfMemoryError,内存不足 内存泄露 线程死锁 锁争用(Lock Contention) Java进程消耗CPU过高 这些问题在日常开发中可能被很多人忽 ...
- Socket详解-Linux Socket编程(不限Linux)
“一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. ——有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览 ...
- python学习笔记011——内置函数pow()
1 语法 pow(x, y[, z]) x -- 数值表达式. y -- 数值表达式. z -- 数值表达式. 函数是计算 x 的 y 次方,如果 z 在存在,则再对结果进行取模,其结果等效于pow( ...
- django1.8forms读书笔记
一.HttpRequest对象的一些属性或方法 request.path,The full path, not including the domain but including the leadi ...
- PHP函数register_shutdown_function的使用示例
某些情况下,我们需要在程序执行结束时,做一些后续的处理工作,这个时候,php的register_shutdown_function函数就可以帮我们来实现这个功能. 函数简介 当PHP程序执行完成后,自 ...
- maven将镜像站点改为中国开源镜像点
在Apache官网上下载bin文件,解压到相应目录.然后配置/etc/profile即可,环境变量名为M2_HOME,如下:(配置完后注意source /etc/profile)#Mavenexpor ...
- Java:HttpClient篇,Cookie概述,及其在HttpClient4.2中的应用
1. Cookie 概述 Cookie是什么? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递.Cookie 包含每次用户访问站点时 Web 应用程序都可以读取 ...
- jquery的animate()方法也可设置非css属性
如题,举例: $('body').animate({scrollTop:0}, 1500); $("body").animate({scrollTop:"-=" ...