可移植/可互操作的 WCF 合约
我想知道是否有人在设计 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 节...
他还指出了关于使用自定义类型作为操作契约方法的参数的问题。 我认为这也适用于方法返回类型。
您可能还想查看 F.4 节。 数据契约,这是他的 WCF 编码标准的一部分。 第 9 条适用于您的问题...
绑定建立期望
基于 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...
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.
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...
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
因此,如果您想与非微软服务进行互操作,您可能需要避开任何非原始类型。 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.