[英]String type in WCF service interpreted as JAXBelement in JavaClient
我有以下WCF Web服務:
[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
}
當我基於上述服務的wsdl在Java客戶端中生成代理類時,對於InwardDocument
類的Citizen
和Remarks
屬性類型,我得到了InwardDocument
。 當我嘗試創建asmx服務的代理類時,情況並非如此。 我應該怎么做才能將字符串作為字符串,將自定義類作為復雜類型,而不是JaxBelement?
在挖掘了很多資源之后,尤其是這一資源和這一資源,並意識到我不是唯一面對這個問題的人之后,我發現有一個名為ObjectFactory的類可以自動生成,借助它我可以輕松地創建某些JAXBElement實例作為輸入傳遞給WCF服務功能。 此類具有與從WSDL生成的JAXBElement數量相同的返回JAXBElement對象的公共實例方法。 假設您有一個JAXBElement LastName輸入。 要將實際數據傳遞到此輸入,您要做的就是:
ObjectFactory factory=new ObjectFactory();
factory.createLastName("Gates");
這樣,使用wcf服務就不會有任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.