使用 Java 访问 WCF 服务

发布于 2024-08-05 03:05:20 字数 406 浏览 3 评论 0原文

我正在使用 WCF 开发一个 Web 服务,我想使用用 Java 编写的客户端来访问它。我将使用 Protocol Buffers 对消息进行编码(Marc Gravell 的 protobuf-net 为精确的)。

这是否可以实现,或者客户端也必须用 .NET 编写?我知道使用 Protocol Buffers 序列化的数据是二进制互操作的,但我不知道 WCF 是否在编码的协议消息之上添加任何特定于平台的元数据。

我不关心 WCF 服务是否是 RESTful、基于 SOAP 或任何其他形式的 WCF 支持,我只希望使用 PB 对实际有效负载进行编码。这是否可能,如果可能,我将非常感谢一个简短的例子。

I'm developing a web-service using WCF, which I want to access using a client written in Java. I will encode the messages using Protocol Buffers (with Marc Gravell's protobuf-net to be exact).

Is this possible to achive or must the client be written in .NET as well? I know that data serialized with Protocol Buffers is binary interopable but I don't know if WCF adds any platform-specific meta-data on top of the encoded protocol-messages.

I don't care if the WCF-service is RESTful, SOAP-based or whatever other forms WCF-support, I just want the actual payload to be encoded using PB. Is this possible and if it is, I would very much appreciate a brief example.

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

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

发布评论

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

评论(2

在梵高的星空下 2024-08-12 03:05:20

如果您对 WCF 服务进行编程以获取字节数组,则可以在其中填充您想要的任何内容,例如 protobuf 消息。可以像

  [ServiceContract]
    public interface IMessageService{
        [OperationContract(IsOneWay = true)]
        void SendMessage(byte[] msg);
    }

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
   public class MessageService: IMessageService{

        public void SendMessage(byte[] msg) {
          //decode the protobuf msg and deal with it.
        }

    }

将 WCF 端点配置为 SOAP 一样简单,然后从
Java 应该是直接的。 WCF/Soap 对此是否会大材小用是另一回事,iirc protobuf 带有自己的简单 RPC 框架。

If you program your WCF service to take a byte array, you can stuff whatever you want in there, like a protobuf message.Could be as simple as

  [ServiceContract]
    public interface IMessageService{
        [OperationContract(IsOneWay = true)]
        void SendMessage(byte[] msg);
    }

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
   public class MessageService: IMessageService{

        public void SendMessage(byte[] msg) {
          //decode the protobuf msg and deal with it.
        }

    }

Configure the WCF endpoint as SOAP, then talking to that from
Java should be straight forward. Whether WCF/Soap would be overkill for this is another matter, iirc protobuf comes with its own framework for simple RPC.

短暂陪伴 2024-08-12 03:05:20

我从未使用过 protobuf-net,但互操作才是重点。

独立于平台 - 可在不同编程架构之间移植

I have never used protobuf-net but interop was the whole point.

platform independent - portable between different programming architectures

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