Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guaranteeing that a .NET WCF Service can be consumed by a Java client

Tags:

java

.net

wcf

I am creating a WCF Service that will be consumed by both .NET and Java client applications.

We do not have any Java experience in the team, so are looking for guidelines or rules to follow to ensure that we do not accidentally include any types in our WCF Service interface or do anything else that would preclude it from being consumed by a Java client application.

Are our worries well-founded? If so, what should we be wary of?

Edit

One example of a concern is whether a .NET DateTime value is represented in the service interface in a manner that can be correctly understood by a Java client.

Edit2

A second example of a concern is the use of any nullable value types (bool?, int? etc).

Edit3

At present some of our development teams are hand-writing .xsd files to define the various objects that the WCF interface methods will take as arguments and return as return values. They are then using xsd.exe to auto-generate C# classes from these.

The rationale behind this is that it guarantees that the generated classes won't contain anything that is .NET-specific.

The downside is that this adds a development burden and also precludes us from documenting these classes using <summary> tags (.NET equivalent of javadoc comments).

like image 978
Richard Ev Avatar asked Mar 27 '09 15:03

Richard Ev


People also ask

Can we call WCF service from Java?

For Java client application, I think you can generate the proxy class from Eclipse and invoke the call to WCF service. The general steps are as follows: Prepare the WCF service and run the service. Create the Java client application in Eclipse IDE, and name the project, like WCFClientApp in this case.

What is a WCF service?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.


2 Answers

The recommendation to start with XSD is a good one. That will not guarantee compatibility on each side, as XML Schema is really big and no web services stack supports all of it. (Example: lists).

So, start with XSD, but confine yourself to mainstream types. Primitives, complextypes composed of primitives, arrays of same. You can safely nest complextypes and arrays. (arrays of complextypes, complextypes that contain arrays or complextypes, etc).

Stay away from restrictions, substitution groups, lists, derivations, and any other XSD esoterica. Even XSD enumerations should be avoided.

About dateTime: It's not enough to use a nullable datetime. There are formatting concerns as well. The .NET DateTime is a higher resolution quantity than a Java Calendar and as a result, shipping a .NET time to Java can result in de-serialization exceptions on the Java side. (EDIT: using the DataType="dateTime" decorator in the XmlElement attribute on the .NET side can make sure you serialize properly)

Some old advice on that.

Finally, it is not true that you cannot use in-code XML doc on the classes that get generated. With C#'s partial classes, you can write separate code from the generated classes with the in-code doc you want. Even if you re-gen the code, your partial class code will remain unchanged. EDIT: When you compile, the doc will appear on the classes.

EDIT: Someone asked, if using XSD-first is not enough to guarantee interop, why use it? My answer: it is not a guarantee but it is a good step, it helps. It keeps you away from designing interfaces in code (either Java or C# or VB, etc) that expose platform-specific things like .NET DataSets, generic Dictionaries, Java ResultSets, etc, all of which present interop problems. There are still pitfalls in the more marginal parts of XSD, but you can usually avoid those with thoughtful design.

I should have mentioned in my original answer that you can apply an iterative process to the development of the interface. Design in XSD, then generate (client) stub and (server) skeleton code from the XSD+WSDL, then adjust and do it again.

like image 62
Cheeso Avatar answered Sep 18 '22 12:09

Cheeso


Using basicHttpBinding endpoint will guarantee that any SOAP 1.1 compatible client will be able to consume your service.

like image 25
Darin Dimitrov Avatar answered Sep 20 '22 12:09

Darin Dimitrov