问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/485580/portable-interoperable-wcf-contracts