Klaasvaak
Klaasvaak

Reputation: 5644

Date SOAP webservice

I'm having a problem sending a java.util.Date object from my C# client to my java webserver. When I am calling a WebMethod with a Date WebParam it works. But if I am calling a WebMethod with a custom object that has a Date as WebParam it's always null.

So, this works:

@WebMethod(operationName="thisWorks")
public void thisWorks(@WebParam(name="from")Date from)
{
    System.out.println(from); //prints the value of the date
}

This doesn't work:

class MyObj { java.util.Date getMyDate(); }

@WebMethod(operationName="thisDoesntWork")
public void thisDoesntWork(@WebParam(name="myObj")MyObj myObj)
{
    System.out.println(myObj.getMyDate()); //prints null
}

Client:

ServiceClient client = new ServiceClient();
client.thisWorks(DateTime.Now);
myObj o = new myObj();
o.myDate = DateTime.Now;
client.thisDoesntWork(o);

Upvotes: 1

Views: 1399

Answers (2)

Edwin Beltran
Edwin Beltran

Reputation: 4459

This issue seems to be the .Net XML Serializer. I did rewrite my code in Java and it works beautifully.

I can think in a way to workaround the {!variable}Specified = true; sentence:

Move the entire declaration of the object to a separated namespace. So, everytime you update the WSDL your code does not get overwritten.

And do not use the System.Nullable<bool> in the property declaration, use bool or DateTime or Double. Get the point?

Upvotes: 1

Klaasvaak
Klaasvaak

Reputation: 5644

The wsdl generates an extra field for the myDate: "bool myDateSpecified". When I set this to true, it works. This is weird, cause when I would have an int field instead of date I also get a specified field for it, but now I dont have to set the specified field for it to work.

Upvotes: 1

Related Questions