为什么我的 WCF 服务器使用 protobuf-net 返回空响应?
我更新了现有的 WCF 应用程序以添加 protobuf-net 支持。 基本上,我已经:
添加了 protobuf-net.dll (.net 3.0) 作为包含所有数据对象的程序集中的引用。我的服务器和客户端都引用此程序集
将 [DataMember] 替换为 [DataMember(Order = x)](使用递增整数作为 x)
使用 ProtoBehavior 属性更新了我的所有 OperationContracts
更新了我的服务引用
从客户端,我在服务器上调用此方法:
[OperationContract(IsOneWay = false), ProtoBehavior]
ConnectionData Join(string userId, string Password);
ConnectionData 的定义如下:
[DataContract]
public class ConnectionData
{
[DataMember(Order = 1)]
public ConnectionStatusEnum ConnectionStatus; // this is a normal enum with five elements
// .....
[DataMember(Order = 5)]
public bool MustChangePassword;
}
现在,发生的情况如下:
如果我调试服务器,我会看到 ConnectionData 对象已正确初始化并在 Join 方法中返回
如果我调试客户端,我会看到从我的 Join 调用返回一个 null 对象
我已启用 WCF 跟踪到最大详细程度,服务器日志中没有任何内容引起我的注意,但在客户端日志文件中我看到了此警告消息:< /p>
System.Runtime.Serialization.ElementIgnored
一个无法识别的元素是 期间在 XML 中遇到 被忽略的反序列化。
元素 http://tempuri.org/:proto
我已经嗅探了我的网络流量,但我没有不要责怪 protobuf-net 无法反序列化此问题:
<s:Body><JoinResponse xmlns="http://tempuri.org/"><proto/></JoinResponse></s:Body>
如何进一步解决问题并让 protobuf-net 正确序列化我的消息?
我正在使用 protobuf-net r275
I've updated an existing WCF application to add protobuf-net support.
Basically, I've :
added protobuf-net.dll (.net 3.0) as a reference in the assembly containing all my data objects. This assembly is referenced by both my server and my client
replaced [DataMember] by [DataMember(Order = x)] (using increasing ints as x)
Updated all my OperationContracts with the ProtoBehavior attribute
Updated my service reference
From the client, I call this method on the server :
[OperationContract(IsOneWay = false), ProtoBehavior]
ConnectionData Join(string userId, string Password);
with ConnectionData being defined like this :
[DataContract]
public class ConnectionData
{
[DataMember(Order = 1)]
public ConnectionStatusEnum ConnectionStatus; // this is a normal enum with five elements
// .....
[DataMember(Order = 5)]
public bool MustChangePassword;
}
Now, here's what's going on :
If I debug the server, I see that a ConnectionData object is correctly initialized and returned in the Join method
If I debug the client, I see a null object being returned from my Join call
I've enabled WCF tracing to the maximum verbosity, nothing caught my eye in the Server's log, but in the Client log file I've seen this warning message :
System.Runtime.Serialization.ElementIgnored
An unrecognized element was
encountered in the XML during
deserialization which was ignored.
Element http://tempuri.org/:proto
I've sniffed my network trafic, and I don't blame protobuf-net for not being able to deserialize this :
<s:Body><JoinResponse xmlns="http://tempuri.org/"><proto/></JoinResponse></s:Body>
How can I further troubleshoot the problem and get protobuf-net to serialize my messages correctly?
I'm using protobuf-net r275
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很抱歉耽误了工作时间等。两端都知道这一变化吗?不幸的是,WCF 集成不能很好地与客户端上“mex”生成的代理配合使用,但可以与程序集共享配合使用。
或者,正在进行一些工作以使用可以在配置中指定的端点行为;这不是 100%,但应该很快 - 并且允许 WCF 透明地使用 protobuf-net,无需对服务合同进行修改(尽管成员仍然需要了解它,可以通过
[ProtoMember(n )]
等,或[DataMember(Order=n)]
。Sorry for the delay - working hours, etc. Do both ends know about this change? Unfortunately, the WCF integration doesn't play very nicely with "mex"-generated proxies at the client, but works OK with assembly sharing.
Alternatively, there is some work in progress to use an endpoint behaviour that can be specified in the config; this isn't 100%, but should be very soon - and allows WCF to use protobuf-net transparently, with no midifications to the service contract (although the members still need to know about it, either through
[ProtoMember(n)]
etc, or[DataMember(Order=n)]
.我在这方面做了更多工作,我怀疑问题是您有一个服务引用(通过 IDE 或通过 svcutil),即使 它重复使用共享数据契约,导致契约接口重复(并丢失行为属性,使其损坏)。
选项:
ClientBase
)如果您不熟悉它们,我计划在接下来的几天内为第一个选项写一篇博客文章。
I've been doing some more work in this area, and I suspect the problem is that you have a service reference (either via the IDE or via svcutil), which even though it re-uses the shared data-contracts, causes the contract interface to get duplicated (and loses the behavior attribute, making it broken).
Options:
ClientBase<T>
)If you aren't familiar with them, I plan on writing a blog entry for the first option in the next couple of days.