Web Services Interoperability between J2EE and .NET - Part 2

Primitive Types

Even primitive types can cause trouble

XML Schema, by providing a rich type model, eases interoperability. You can construct WSDL messages and operations because the XML Schema identifies specific data types that a Web service uses. XSD offers a wide range of types and simple structs. However, each programming language has a set of native data types. A one-to-one mapping is not available between native data types and XSD data types. Therefore, information can be lost during the translation, or the receiver is simply unable to do the mappings for certain native data types.

Unsigned numerical types, such as xsd:unsignedInt, xsd:unsignedLong, xsd:unsignedShort , and xsd:unsignedByte , are the typical examples. In .NET, the uint, ulong, ushort , and ubyte types map directly to those xsd types, but the Java language does not have unsigned numerical types. For interoperability, do not expose those numerical data types in the Web service methods. Instead, you can create wrapper methods to expose and transmit those numerical types as xsd:string (using System.Convert.ToString in C#).

For xsd:decimal, xsd:double , and xsd:float types, each platform might have different precision support. As a result, loss of precision might occur if you do not test the Web service after integration.

Whether a data type is a value type or a reference type, the communicating parties could also pose problems. The object of a value type is in the stack, but the object of a reference type is in the heap. That means a reference type can have a null pointer, but a value type cannot have a null value. This can lead to a problem if the XSD type is mapped to a value type in one language but mapped to a reference type in another. For example, the xsd:dateTime is mapped to System.DateTime , which is a value type in C#. It is also mapped to java.util.Calendar , which is a reference type in Java. In fact, both java.util.Date and java.util.Calendar are reference types. In Java, it is a common practice to assign a null value to a reference type when it is not referencing any object. However, .NET Web services will throw a System.FormatException if it receives a null value to its value type of data from a Java client. To avoid this problem, you can define a complex type to wrap the value type and set the complex type to be null to indicate a null reference.


In this article, you have seen some interoperability problems resulting from the use of certain data types. The general rules to achieve better interoperability in using data types are:

  • Stick with the simple data types as much as possible. Totally avoid those fancy compex types such as ArrayList , Tree , and even the common Hashtable .
  • Even though plain arrays are generally fine with interoperating Web services, be careful of what is in the arrays, make sure the elements in an array have the same meaning in both platforms, and avoid sending an array with null elements.
  • Be conscious about how each platform implements some native primitive types such as float , double , and dates and times .
In the next part of this series, I will explore the impact of namespace on the Web Service interoperability.

You might also like...


About the author

Wangming Ye United States

Wangming Ye is an IBM Certified Enterprise Developer and a Sun Certified Enterprise Architect for J2EE Technology. He began as a developer in the DCE/DFS department at Transarc Corporation (late...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup