Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 23,755 times

Contents

Related Categories

Web Services Interoperability between J2EE and .NET - Part 2 - Primitive Types

Wangming Ye

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.

Conclusion

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.

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 (later merged into IBM), and then as one of the main developers of the WebSphere Content Distribution Framework in the WebSphere Edge Server group. He currently provides technical enablement for WebSphere business partners in the WebSphere Competency Center in the IBM Business Partner Technical Enablement organization.

Comments

  • Null parameters

    Posted by nrsimoes on 16 Jan 2006

    I'm developing a .NET Web Service that have some functions with datetime parameters but the I can't call it from Java client with nulls. Can you explain me how to define a complex type to wrap the val...

  • But how... ?

    Posted by stefantura on 14 Jul 2005

    Hi,

    Nice article - but what sould go next - some examples (or maybe names of solutions) of software which translates between different SOAP datatypes... There have to be such a frameworks for type ...