如何在客户端中使用apache cxf jaxb数据绑定

时间:2017-03-06 14:50:20

标签: json xml jaxb cxf jax-ws

如何编写cxf ws的客户端代码在方法参数或返回类型中使用xml / json / pojo? 这是我写的代码的一部分:

我的实体代码是:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Company implements Serializable{
    private static final long serialVersionUID = 2735346136202386685L;
    private String id;
    private String name;
...

我的服务器代码是:

@WebService(name="CompanyService",targetNamespace="http://test.cxf.com")
public interface CompanyServiceIF extends Remote{
    /**
     * add a new company
     * 
     * @param company
     * @return
     */
    @WebResult(name = "addByObjectResponse", targetNamespace = "http://test.cxf.com/", partName = "parameters")
    @WebMethod(operationName = "add", action = "urn:addCompany")
    String addCompany(@WebParam(name="company")Company company);
...

我的客户代码是:

JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();  
Client client = clientFactory.createClient("http://127.0.0.1:8080/CXFTest/companyService?wsdl");
client.getInInterceptors().add(new LoggingInInterceptor());  
client.getInFaultInterceptors().add(new LoggingOutInterceptor());  
QName serviceName=new QName("http://test.cxf.com", "add");
Object[] result = client.invoke(serviceName, "");

0 个答案:

没有答案