Library tutorials & articles
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.
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 .
Related articles
Related discussion
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Read HSQLDB data into a webpage
by joe90 (3 replies)
-
Problem in Java Script
by windshadow2005 (0 replies)
-
Changing Technology from .NET to Java/J2EE
by ramkinkarpandey (0 replies)
-
Difficulties Consuming Java Web Services in .NET
by adev111 (3 replies)
Related podcasts
-
Open Source SOA
The focus of this session will be to demonstrate innovative open source technologies and give you an insight into the skills, tools and techniques for SOA-enabling your enterprise architecture. This session will be taught via lecture as well as interesting live demonstrations (e.g. .NET linking t...
Events coming up
-
Nov
18
15 Minutes of Fame
Dresher, United States
This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.
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 value type and set the complex type to be null to indicate a null reference?
Thanks
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 matching, aren't these?
--
best regards
stic
This thread is for discussions of Web Services Interoperability between J2EE and .NET - Part 2.