从.proto rpc条目生成FaultContract属性

发布于 2024-09-18 11:56:02 字数 464 浏览 5 评论 0原文

我在我正在处理的数据合约项目中使用 protobuf-net,手动创建 .proto 文件,并让自定义工具输出它正在执行的 C# 代码。 我也开始将它用于服务合同,并且服务接口也创建得很好。

为了连接到某些系统,我正在使用 WCF,因此我启用了 datacontracts 生成器选项,尽管存在 System.ServiceModel 属性,但似乎没有任何我可以声明该服务可能引发的具体错误的方式。

所以我的问题基本上是:

  • Protocol Buffers 语言似乎没有任何异常/错误的构造。
  • 我看不到任何用于生成FaultContract 属性的protobuf-net 选项。
  • protobuf-net 生成的接口未声明为部分的,因此我无法扩充生成的代码。

有没有办法在 protobuf-net 中声明服务 WCF 操作错误,或者我必须等待版本 2?

非常感谢。

I am using protobuf-net on the project I am working on for the data contracts, creating the .proto files by hand and having the custom tool spew forth the C# code which it is duly doing.
I have also started using it for service contracts and the service interfaces are also created just fine.

For connectivity to some systems I am using WCF so I have enabled the datacontracts generator option and, although the the System.ServiceModel attributes are present, there does not appear to be any way for me to declare the specific faults the service may raise.

So my problem is basically:

  • Protocol Buffers language does not appear to have any constructs for exceptions/faults.
  • I cannot see any protobuf-net options for generating FaultContract attributes.
  • The interface generated by protobuf-net is not declared partial so I cannot augment the generated code.

Is there any way to declare service WCF operation faults in protobuf-net or is this something that I would have to wait for version 2 for?

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

国际总奸 2024-09-25 11:56:02

我不知道为什么我不将其声明为部分接口,因为这在 C# 2.0 中似乎非常满意;当我有时间时我会进行更改,但请注意,您可以在本地应用手动更改 - 只需编辑 csharp.xslt 文件即可。现在,xslt 并不是每个人都喜欢的,但它应该是 1 行更改(靠近单词 interface) - 事实上,它可能是添加了 partial 此处:

<xsl:template match="ServiceDescriptorProto">
    <xsl:if test="($optionClientProxy or $optionDataContract)">
    [global::System.ServiceModel.ServiceContract(Name = @"<xsl:value-of select="name"/>")]</xsl:if>
    public /* HERE => */ partial /* <= HERE */ interface I<xsl:value-of select="name"/>
    {
      <xsl:apply-templates select="method"/>
    }

    <xsl:if test="$optionProtoRpc">
    public class <xsl:value-of select="name"/>Client : global::ProtoBuf.ServiceModel.RpcClient
    {
      public <xsl:value-of select="name"/>Client() : base(typeof(I<xsl:value-of select="name"/>)) { }
      <xsl:apply-templates select="method/MethodDescriptorProto" mode="protoRpc"/>
    }
    </xsl:if>
    <xsl:apply-templates select="." mode="clientProxy"/>

</xsl:template>

由于 xslt 是可调整的,因此您应该能够应用您需要的任何其他更改。

I'm not sure why I don't declare that as partial interface, since that seems perfectly happy in C# 2.0; I'll get that changed when I get a second, but note that you can apply a manual change locally - simply by editing the csharp.xslt file. Now, xslt isn't everyone's cup of tea, but it should be a 1-line change (near to the word interface) - in fact, it is probably the addition of partial here:

<xsl:template match="ServiceDescriptorProto">
    <xsl:if test="($optionClientProxy or $optionDataContract)">
    [global::System.ServiceModel.ServiceContract(Name = @"<xsl:value-of select="name"/>")]</xsl:if>
    public /* HERE => */ partial /* <= HERE */ interface I<xsl:value-of select="name"/>
    {
      <xsl:apply-templates select="method"/>
    }

    <xsl:if test="$optionProtoRpc">
    public class <xsl:value-of select="name"/>Client : global::ProtoBuf.ServiceModel.RpcClient
    {
      public <xsl:value-of select="name"/>Client() : base(typeof(I<xsl:value-of select="name"/>)) { }
      <xsl:apply-templates select="method/MethodDescriptorProto" mode="protoRpc"/>
    }
    </xsl:if>
    <xsl:apply-templates select="." mode="clientProxy"/>

</xsl:template>

Since the the xslt is tweakable, you should be able to apply any other changes you require.

猥︴琐丶欲为 2024-09-25 11:56:02

这并不能直接回答您的问题,但无论如何可能是合适的
protobuf-net 不需要 .proto 文件才能工作,因此只需编写 C# 类并使用 WCF 属性(和您的 FaultContract 属性)装饰它们与(手动)为为了生成 C# 类。

this doesnt directly answer your question but may be appropriate anyway
protobuf-net doesn't need .proto files to work, so it would be the same amount of effort to just write your C# classes and decorate them with the WCF attributes (and your FaultContract attributes) than create the proto's (manually) for the sake of generating C# classes.

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