tags:

views:

203

answers:

1

I have create a web service in glassfish v3. The method I am try to call from .net using generated client in visual studio 2008 takes a single parameter which is basically a java bean - simple types (Double, String, Date) as fields with getters and setters (Actually it is an EJB entity class). I find that when I call the method from my c# client that the null values are received for the Double and Date parameters (but not for String ones) by the server. Interestingly, I was also having this problem within a java net beans generated client until I made the fields of the bean protected instead of private in the web service implementation, but in the java case all non primitive types including String came in as null.

Since the java client now works it seems the problem is with the way .net is marshalling the data. I am wondering if I can change the way the server generates the wsdl using annotations on the server side so that .net interprets it in the right way, or somehow control how .net generates the client - using parameters to a command line tool rather than generating the client using visual studio for example. I don't really want to build a client by hand.

+1  A: 

The classes that are generated on the .NET side may include "FooSpecified" field used to indicate if the "Foo" property/field is set. These are an unfortunate side-effect of those types (Double, DateTime) being nullable in SOAP/WebServices/Java, but not being nullable in .NET. Instead of Nullable for the field, instead there may be an additional boolean field used to indicate if those fields are specified or not. Try explicitly setting those fields to true before sending them to your web service.

Pete
Wow that was quick - I got my answer in less than 10 minutes! Thanks very much. I tried your suggestion and it does indeed work. However as you imply, not the prettiest interface. Is it possible to customise the way .NET maps types during the generation of the client code so that .net nullable types are used? Being able to control type mapping would be useful in other contexts, e.g. say you want map a xsd:decimal on to user defined type rather than a .net decimal so that you could preserve the semantics of javas BigDecimal for instance.
Shane
I'm not aware of any way to use Nullable<T> or other type mapping instead, sadly. That would be an excellent alternative to the FooSpecified hack.
Pete