为什么我的 WCF 服务器使用 protobuf-net 返回空响应?

发布于 2024-08-08 03:46:44 字数 1512 浏览 8 评论 0原文

我更新了现有的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒浓于脸红 2024-08-15 03:46:44

很抱歉耽误了工作时间等。两端都知道这一变化吗?不幸的是,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)].

红焚 2024-08-15 03:46:44

我在这方面做了更多工作,我怀疑问题是您有一个服务引用(通过 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:

  • don't use a service-reference (use the channel directly, or subclass ClientBase<T>)
  • use the new endpoint configuration options
  • hack the generated interface to include the behavior (creates maintenance problems)

If you aren't familiar with them, I plan on writing a blog entry for the first option in the next couple of days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文