.Net Remoting Exception: BinaryFormatter Version Incompatibility

.Net Remoting Exception: BinaryFormatter Version Incompatibility

 

 

在开发.Net Remoting的程序时,发现了如下异常消息:

Exception Message:

An unhandled exception of type 'System.Runtime.Serialization. SerializationException' occurred in mscorlib.dll

Additional information: BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 1008738336.1684104552.

注:由IIS承载Remote Objects,并且采用BinaryFormatterHTTPChannel

 

然后在Ingo Rammerweb site-.Net Remoting FAQ发现了对上述异常信息的分析及其解决办法,详见下面的Reference 1

 

*** Cause ***

其实这和Version Incompatibility完全没有关系,事实上是由于Client端的Binary Formatter总是尽量以二进制编码的格式去解析从Server端获取的返回值造成的。

 

假设ServerRemote Objects出现异常,返回如下异常信息:

HTTP/1.1 500 Internal Server Error

……

事实上,Client端却以二进制编码的格式来解析,它首先检查header头,寻找Server端使用的Serializer版本号,结果没有接受到版本号,而是读取"<htm...",并解析为"1008738336.1684104552"。然后比较1.01008738336.1684104552,并认为发生Version Incompatibility异常。

 

*** Solution ***

没有通用的解决办法,一般而言这是ServerRemote ObjectsRemote method发生异常。不过,可以按照如下的思路进行分析:

 

1,确保Remote Objects部署正常

可以通过如何检测Remote Objects是否部署成功来进行验证。

 

2,使用Simon Fell提供tcpTrace工具来捕获ClientServer间传输的数据

1)先从http://www.pocketsoap.com 下载tcpTrace工具。

2)然后,需要将ClientServer端的BinaryFormatter改为SOAPFormatter,否则tcpTrance也只是简单捕获Header信息,没有SOAP消息体的信息。

3)启动tcpTrace,并配置参数:

  • Listen on Port #: 81
  • Destination Server: localhost
  • Destination Port #: 80

    假设Remote Serverlocalhost,并且port80,然后Listen on Port设置为:81(当然可以为其他)。

    下一步需要调整ClientConfiguration file或者Source code,连接的Server URL设置为81(而不是80)。

4)通过分析tcpSoapSOAP消息,查看Server真正返回的异常信息,找到真正的错误。

 

上述技术仅对SAOwellknown)对象有用。对CAO对象而言,由Server端产生URL并包含真正的Port号。

解决问题后,最后别忘了恢复ClientPort

 

References:

1, Ingo Rammer, .Net Remoting FAQ, http://www.thinktecture.com/Resources/RemotingFAQ/BINARYVERSIONMISMATCH.html

 

posted @ 2004-10-28 04:51  Rickie  阅读(4208)  评论(1编辑  收藏  举报