2

There is a .net client which calls java web services api - addSchedule(Date startDate, Date endDate). endDate is optional - i.e client can pass endDate= null and all is fine. But the issue is- .Net client cannot assign null to Date variable type.

One more thing we checked, if java web service response passes the null Date value to .net client, this is received as Date.MIN_VALUE by .Net. So we thought what if .Net passes endDate=Date.MIN_VALUE,so java will get the endDate=null. But java is getting Date.MIN_VALUE as valid date.

So we are stuck. Please suggest a good workaround.

2 Answers 2

2

Try using a Nullable DateTime (Nullable<DateTime> or DateTime?), since this can hold a null value. A normal value type (like DateTime) can't hold null, and will have a default value (in the case of DateTime this is DateTime.MinValue, but for int it is 0)

7
  • When we pass Nullable<DateTime>, It says you cannot pass Nullable<DateTime>, DateTime is expected in addSchedule Jul 15, 2011 at 13:47
  • You need to make all the related code use DateTime?/Nullable<DateTime> or use the Value property (note: if you access the Value property when it is null, it will throw an exception! You can use the HasValue property to check, or compare it to null. Jul 15, 2011 at 13:55
  • I don't have much experience with .Net. Just curious what should be the Date dataType on java side in addSchedule, So that on .net side the client wrapper call looks like AddSchdule(DateTime, Nullable<DateTime>) Jul 15, 2011 at 13:59
  • If DateTime's are nullable in Java, then you want to use DateTime? (which is just short for Nullable<DateTime>) wherever you need to use them in .NET. If the values will never actually be null, you can read the Value property from the DateTime?. Otherwise, you'll need to fix up all the code to correctly handle the nulls or Values. I's hard to be more specific without knowing exactly what code you're writing, what is being generated, how they're talking to each other, etc. Jul 15, 2011 at 16:39
  • In Java, any Object can be assigned 'null', so is Date object.Webservice method- addSchedule(Date startDate, Date endDate) can be invoked by java client- addSchedule(new Date, null). No issues at all. .Net client,which generates client proxy with Java webservice WSDL results to AddScheule(DateTime, DateTime). But .net client cannot invoke with null value AddSchedule(currentDate, null). Using Nullable<DateTime>: Nullable<DateTime> endTime = Null; EndPoint.AddSchedule(currentDate, endTime).It throws type mismatch error, refer 1 comment above. Jul 15, 2011 at 17:31
0

We need to add nillable=true in Java webservice method :- addSchedule(Date startDate, @XmlElement(nillable=true) Date endDate) . With this new wsdl definition, .Net client generates AddScheule(DateTime, <Nullable>DateTime).This is supported by metro 2.2 version jars (jaxb and jaxws.jar). If jre6 has a old version of these jars, download the 2.2 version of these jars and place in the JRE_HOME/lib/endorsed folder. Use the same jre path to build your project.

And when deploying the application on tomcat, copy jaxb and jaxws.jar [2.2 version] in the directory CATALINA_HOME/endorsed. You are good to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.