String type in WCF service interpreted as JAXBelement in JavaClient

别说谁变了你拦得住时间么 提交于 2019-12-12 03:47:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32011067/string-type-in-wcf-service-interpreted-as-jaxbelement-in-javaclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!