WCF异常System.ServiceModel.ProtocolException问题处理
现象:
最近遇到了WCF 服务无法调用的错误,异常如下。
System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Error while reading message framing format at position 0 of stream (state: ReadingUpgradeRecord)
System.IO.InvalidDataException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 More data was expected, but EOF was reached.
日志
WCF的问题一般需要对框架比较熟悉,有时难以定位。第一眼找不到原因的先 根据官方文档打开WCF日志
日志打开后发现服务端完全没有调用的记录。这时怀疑是不是调错端口了,打开资源管理器,服务正常跑着。只能再打开Wireshark记录日志,大概就是正常的3次握手,不正常的不知为何服务端主动FIN并RESET的连接。
在WCF的问题处理中,自己的日志/WCF的日志/抓包的日志都很重要。
原因
最后的原因发现是端口被罗技升级程序占用的问题, 考虑如下示例代码
// 设置要监听的端口号
int port = 13000;
TcpListener listener = new TcpListener(IPAddress.Any, port);
TcpListener listener2 = new TcpListener(IPAddress.Loopback, port);
// 开始监听
listener.Start();
listener2.Start();
// 并不会抛出异常
Console.ReadLine();
工作久了过于相信经验,感觉一定会异常,但端口监听的是套接字,自然0.0.0.0:13000 和 127.0.0.1:13000不是一回事。
WCF异常原理
wcf的通信流程大概是这样的。
// 客户端发送服务端基地址,确认这是一个wcf的服务
client-> service: net.tcp://127.0.0.1:39100/Service
// 服务端回0b 代表确认
service-> client: 0x0b
// 客户端发送具体调用的内容
.....
由于服务端不回 0x0b,自然会出现这样的异常。附一下异常的调用栈。事后看看也挺明显。
System.ServiceModel.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(Byte[] buffer, Int32 count, ClientFramingDecoder decoder, Uri via)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
...
WCF异常System.ServiceModel.ProtocolException问题处理的更多相关文章
- WCF部署到IIS异常(详细: 不能加载类型System.ServiceModel.Activation.HttpModule )
未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“ ...
- 【WinForm】“System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常,无法识别的配置节 system.serviceModel
出现问题的原因: 在本机上没有出现问题,让一个同事测试的时候,在另外一台电脑上出现连接数据库失败,系统不能打开的问题 在网上搜了一下,有说是数据库连接字符串错误的,有说app.config文件配置不匹 ...
- 【使用WCF,发布服务端浏览报错】未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” 中加载类型 “System.ServiceModel.Activation.HttpModule”。
问题: 在WIN7中的IIS服务器中部署WCF服务程序时,通过浏览器访问报出如下错误: 未能从程序集"System.ServiceModel, Version=3.0.0.0, Cultur ...
- WCF入门教程(四)通过Host代码方式来承载服务 一个WCF使用TCP协议进行通协的例子 jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding System.ServiceModel.WSHttpBinding协议 学习WCF笔记之二 无废话WCF入门教程一[什么是WCF]
WCF入门教程(四)通过Host代码方式来承载服务 Posted on 2014-05-15 13:03 停留的风 阅读(7681) 评论(0) 编辑 收藏 WCF入门教程(四)通过Host代码方式来 ...
- jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding
Jquery ajax调用WCF服务 例子效果如下:原界面 点击按钮GetList get后,通过指定的Url获取数据添加到table 新建一个控制台项目,添加IContract.cs,DBServi ...
- jquery ajax调用WCF,采用System.ServiceModel.WSHttpBinding协议
采用System.ServiceModel.WSHttpBinding或者basicHttpBinding 协议.客户端就不能直接在前端通过url直接访问服务了 它是基于SOAP协议的bing,会采用 ...
- WCF项目问题1-找不到类型“WCFService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。
找不到类型“WCFService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHosti ...
- System.ServiceModel.CommunicationException: 接收HTTP 响应时错误发生
具体错误信息例如以下: System.ServiceModel.CommunicationException: 接收对 http://110.110.110.110/TestService/TestS ...
- 通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。
通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态. 在 System.ServiceModel.Channels. ...
- 未能加载文件或程序集“System.ServiceModel, Version=2.0.5.0, ...”解决方法
未能加载文件或程序集“System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它 ...
随机推荐
- es 排序突然很慢的原因
今天突然之间发现一个访问es的查询很慢.由刚上线之前测试的100ms直接到了5s左右.瞬间懵逼. 这个用户索引大概200w的数据. 查询语句如下 GET /user/_search{"fro ...
- mysql通过binlog来恢复被删除的数据库
binlog日志 查询: MariaDB [(none)]> show variables like 'log_bin'; +---------------+-------+ | Variabl ...
- windows7 + Qt(MSVC2017) + VS2019安装配置
在windows下使用qt时调用QWebEngineView 库会报错,即使在pro文件QT += webenginewidgets也找不到, 而在MinGW和MSVC2015的路径下我并没有找到这个 ...
- 「C++」深度分析C++中i++与++i的区别
大家好,我是Charzie.在C++编程中,i++和++i是两个常见的自增运算符,用于将变量的值增加1(有时与i+=1效果一样).然而,虽然它们的功能看似相似,但在实际使用中却存在显著的区别.本博客将 ...
- python-去掉写入csv文件的多余的一行空白行
如执行下面的代码: 1 import csv 2 3 if __name__ == "__main__": 4 5 content1 = ['hello'] 6 content2 ...
- python实现取得成员所在的多个位置
注:本代码主要是为了实现多个集合之间求并集时的辅助代码,简单的举个例子来说明代码的功能. 约定:例如{11: [2, 3]}表示数据11在集合2和集合3中都存在. 现有以下数据: d0 = {38: ...
- SpringBoot系列(七) jpa的使用,以增删改查为例
JPA是Java Persistence API的简称,Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 它是SUN公司推出的一套基 ...
- java.util.Date和java.sql.Date有什么区别?
java.util.Date包含日期和时间,而java.sql.Date只包含日期信息,而没有具体的时间信息.如果你想把时间信息存储在数据库 里,可以考虑使用Timestamp或者Date ...
- python 日志写入文件,参数说明及动态判断文件是创建还是追加
import logging import os ''' 格式符 含义 %(levername)s 日志级别名称 %(pathname)s 当前执行程序的路径(即脚本所在的位置) %(filename ...
- Woothosting 6$/年 vps测评
当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解 Woothosting 6$/年 vps测评** 日期:2018-7- ...