Search code examples
javawcfjaxbelement

String type in WCF service interpreted as JAXBelement in JavaClient


I have the following WCF web service:

[ServiceContract]
interface IService
{
    [OperationContract]
    void SaveInwardDocument(InwardDocument document);
}

public class Serice:IService{
   void SaveInwardDocument(InwardDocument document){...};
}

[DataContract]
public class InwardDocument{
   [DataMember]
   public Citizen {get;set;}
   //some other enum properties
   [DataMember]
   public string Remarks {get;set;}
}

[DataContract]
public class Citizen{
   //Citizen proeperties
}

When I generate a proxy class in a java client based on the wsdl of the above service, I get JaxBelement for the type of Citizen and Remarks properties of the InwardDocument classes. That's not the case when I try to create proxy class of an asmx service. What do I have to do to get string as string and custom class as a complex type, not JaxBelement?


Solution

  • After digging lots of resources, especially this one and this one and realizing that I was not the only one facing this issue I found out that there is a class called ObjectFactory that is generated automatically with the help of which I can easily create certain JAXBElement instances to be passed as inputs to a WCF service function. This class has as many public instance methods that return JAXBElement objects as the number of JAXBElement generated from WSDL. Say you have a JAXBElement LastName input. To pass the actual data to this input all you have to do is this:

     ObjectFactory factory=new ObjectFactory();
     factory.createLastName("Gates");
    

    This way, you shouldn't have any issues consuminga wcf service.