jaxws复杂类型包

时间:2012-07-18 01:38:21

标签: java wcf jax-ws jax-ws-customization

假设我使用wsimport使用jaxws soap生成的客户端消耗了WCF服务。 服务SEI看起来像

@WebMethod(operationName = "DoSomething", action = "http://mydomain.com/PersonService/Dosomething")
@WebResult(name = "DoSomethingResult", targetNamespace = "http://mydomain.com/")
@RequestWrapper(localName = "DoSomething", targetNamespace = "http://mydomain.com/", className = "webservice.jaxws.DoSomething")
@ResponseWrapper(localName = "DoSomethingResponse", targetNamespace = "http://mydomain.com/", className = "webservice.jaxws.DoSomething")
public Person doSomething(
    @WebParam(name = "person", targetNamespace = "http://mydomain.com/")
    Person person);

采用复杂类型Person并返回相同类型Person并生成DoSomething看起来像

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
  "person"
})
@XmlRootElement(name = "DoSomething")
public class DoSomething {

@XmlElement(nillable = true)
protected Person person;
public Person getPerson() {
    return person;
}
public void setPerson(Person value) {
    this.person = value;
}

如果Person与DoSomething是相同的包,一切正常,只要我将Person移动到其他地方,WCF服务无法从Person对象中获取任何内容(字段为null或0),WCF的返回值无法正确保存通过JAXWS,虽然没有例外。

我注意到如果它们在同一个包中,那么将调用setPerson,但如果它们位于不同的包中则不会。

我想知道是否可以将复杂类型Person放在另一个包中作为DoSomething。

1 个答案:

答案 0 :(得分:1)

事实证明需要在Person的包

中使用神奇的package-info.java文件