可移植/可互操作的 WCF 合约

发布于 2024-07-13 00:17:17 字数 210 浏览 9 评论 0原文

我想知道是否有人在设计 WCF 合约时考虑到 Web 服务互操作性时是否有一些好的提示/注意事项,无论是旧的 Microsoft Web 服务技术(例如 WSE)还是非 Microsoft 技术(例如Java 调用 WCF Web 服务。

例如:在合约中将 DateTime 作为类型公开时是否需要考虑任何特殊规则? 字典和哈希表怎么样? 使用各种可用的绑定可能会遇到哪些问题?

I was wondering if anybody out there had some good tips/dos and don'ts for designing WCF contracts with a mind for web-service interoperability, both in terms of older Microsoft web service technologies (e.g. WSE) and non-Microsoft technologies such as Java calling WCF web services.

For example: are there any special rules that need to be taken into account when exposing DateTime as a type in your contract? How about Dictionaries and Hashtables? What are the issues you might run into with the various bindings available?

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

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

发布评论

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

评论(2

(り薆情海 2024-07-20 00:17:17

WCF DateTime 问题

关于您的 DateTime 问题,您对通过 WCF 传递 DateTime 的担忧是正确的。 这只是许多抱怨困难的链接之一......
http://daveonsoftware.blogspot.com/2008/07/wcf -datetime-field-adjusted.html

关于类型等效性

根据 Juval Lowy 的书《Programming WCF Services, 2nd Edition》第 3.1.3 节...

WCF 提供隐式数据契约
原始类型,因为有
模式的行业标准
这些类型。

他还指出了关于使用自定义类型作为操作契约方法的参数的问题。 我认为这也适用于方法返回类型。

能够使用自定义类型作为
操作参数,有两个
要求:首先,类型必须是
可序列化,其次,两者
客户端和服务需要有一个
该类型的本地定义
结果相同的数据模式。

您可能还想查看 F.4 节。 数据契约,这是他的 WCF 编码标准的一部分。 第 9 条适用于您的问题...

不要传递 .NET 特定类型,例如
作为类型,作为操作参数。

绑定建立期望

基于 WSHttpBindingBase(在 Reflector.NET 中搜索其四个派生版本)的绑定将是最具互操作性的,因为它们是为互操作性而设计的。

书籍推荐

我强烈推荐Juval的书:http://www.bookpool.com/sm/0596521308

WCF DateTime woes

Regarding your DateTime question, you are right to be concerned about passing around DateTime via WCF. This is just one link of many that gripe about the difficulties...
http://daveonsoftware.blogspot.com/2008/07/wcf-datetime-field-adjusted.html

Regarding Type Equivalence

According to section 3.1.3 of Juval Lowy's book entitled Programming WCF Services, 2nd Edition...

WCF offers implicit data contracts for
the primitive types because there is
an industry standard for the schemas
of those types.

He also points that out in regards to the use of custom types as parameters on Operation Contract methods. I presume this also applies to method return types.

To be able to use a custom type as an
operation parameter, there are two
requirements: first, the type must be
serializable, and second, both the
client and the service need to have a
local definition of that type that
results in the same data schema.

You may also want to check out section F.4. Data Contracts, which is part of his WCF Coding Standard. Bullet #9 applies to your question...

Do not pass .NET-specific types, such
as Type, as operation parameters.

Bindings Establish Expectations

Bindings that are based on WSHttpBindingBase (search in Reflector.NET for its four derivations) are going to be the most interoperable, since they are designed for interoperability.

Book Recommendation

I highly recommend Juval's book: http://www.bookpool.com/sm/0596521308

相守太难 2024-07-20 00:17:17

因此,如果您想与非微软服务进行互操作,您可能需要避开任何非原始类型。 WCF 使用序列化来编码数据以进行传输,而 Java 则无法反序列化哈希表。 然而,WCF 是构建在 SOAP 之上的,因此通过一些工作,您应该能够在 JAVA 客户端和 WCF 服务之间使用任何 SOAP 功能,反之亦然。

只要记住编写原语合约就可以了。

So if you want to interop with non microsoft services you will probably want to steer clear of any non-primitive type. WCF uses serialization to encode data for transmission and Java for instance will not be able to deserialize a hashtable. WCF however is build on top of SOAP so with a bit of work you should be able to get any SOAP feature working between a JAVA client and WCF Service or vice-versa.

Just remember to compose contracts of primitives and you should do okay.

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