到多个端点的 WCF 服务

发布于 2024-10-05 17:56:59 字数 150 浏览 0 评论 0原文

我如何确保可以从任何其他语言(Java、PHP、iOS 使用的任何语言等)访问我的 WCF 服务?

我将所有内容保留为 httpbinding,并且没有为客户端使用任何 .net 角色/成员身份验证。但有些事情我不确定。比如,我可以返回一个可由其他语言读取的通用列表吗?

How do I go about making sure that my WCF service can be accessed from any other language(Java, PHP, whatever iOS uses, etc.)?

I have kept everything as httpbinding plus not used any of the .net roles/membership authentication for the clients. But there are some things that I am not sure of. Like, can I return a generic List that is readable by those other languages?

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

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

发布评论

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

评论(2

半暖夏伤 2024-10-12 17:57:01

任何不以 net 开头的 WCF 绑定(netTcp、netMsmq 等)都应该没问题 - 它们被设计为可互操作。

最基本的是 basicHttpBinding,它几乎是普通的 HTTP - 没有什么可以添加到其中。您应该能够从任何脚本语言(PHP 等)调用它。

更高级的绑定是 wsHttpBinding,它实现了许多 WS-* 标准,并且可以从网络堆栈可以处理 WS-* 的其他语言(例如 Java 等)进行调用。

然后是 webHttpBinding 它不是通过 SOAP 而是通过 REST 端点公开您的服务。这应该可以从任何语言、任何设备、任何地点调用。

当然,如果您从服务中公开多个端点,为试图呼叫您的任何人提供多种选择,您将获得最佳覆盖范围。所有这些都只需在配置中完成 - 无需更改代码即可支持多个端点、多个绑定等。

至于列表和内容:WCF 交换序列化消息 - 基本上是 XML - 由 XML 模式管理。 WSDL 和 XSD 的组合是完全可互操作的,并且可以被多种其他语言理解。

.NET 中的 List 将转换为 XML 结构中的数组,这是完全可互操作的 - 不用担心。客户端可能只是返回一个数组而不是列表 - 但这不是问题。

唯一的问题是您无法真正对通用列表进行建模,因为 XML 架构不支持泛型 - 您需要明确说明要发送回的内容。 List 不起作用 - List 可以(如果您的 Customer 对象是数据协定的一部分并标记为像这样)

Any of the WCF bindings that don't start with net (netTcp, netMsmq etc.) should be fine - they're designed to be interoperable.

The most basic one is basicHttpBinding which is pretty much plain HTTP - nothing much can be added to it. You should be able to call this from any scripting language (PHP etc.).

The more advanced binding is wsHttpBinding which implements lots of the WS-* standards and can be called from other languages where the networking stack can handle WS-* - stuff like Java etc.

And then there's the webHttpBinding which exposes your service not via SOAP, but via a REST endpoint. This should be callable from just about any language, any device, any place.

And of course, you get the best coverage if you expose multiple endpoints from your service, offering a variety of choices to anyone trying to call you. All this is done simply in config - no code change necessary to support multiple endpoints, multiple bindings etc.

As for lists and stuff: WCF exchanges serialized messages - basically XML - which is governed by a XML schema. The combination of a WSDL and XSD is totally interoperable and can be understood by a wide variety of other languages.

A List<T> in .NET will be turned into an array in your XML structure, and that's totally interoperable - don't worry. The client might just get back an array instead of a list - but that's not a problem.

The only problem is that you cannot really model a generic list, since the XML schema doesn't support generics - you need to be explicit about what it is you're sending back. A List<T> won't work - a List<Customer> will (if your Customer object is part of your data contract and marked as such)

独守阴晴ぅ圆缺 2024-10-12 17:57:01

如果您对用于使用服务的客户端技术没有任何控制权,则您无法 100% 确定。但如果您的 Web 服务 (WSDL) 符合 WS-I 基本配置文件 v1.1。该标准受到广泛支持且成熟。您可以使用优秀的 SoapUI 测试工具来测试 WSDL 的一致性。

You cannot be 100% sure if you don't have any control over the client technology that is used to consume your services. But you can be very confident if your web service (WSDL) conforms to the WS-I basic profile v1.1. This standard is very widely supported and mature. You can use the excellent SoapUI test tool to test your WSDL for conformance.

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