如何通过CXF Jax-ws发送Message对象类型

时间:2015-11-19 13:46:01

标签: java cxf cxf-client

我想通过CXF Jax-ws发送一个org.apache.cxf.message.Message对象。例如:

  1. 宣布服务:

    @WebService
    public interface HelloWorld {
        void send(Message msg);
    }
    
  2. 此服务的实施:

    public class HelloWorldImpl implements HelloWorld {
        public void send(Message msg) {
            System.out.println("receives msg id:" +((MessageImpl)msg).getId());
        }
    }
    
  3. 服务器:

    HelloWorldImpl implementor = new HelloWorldImpl();
    JaxWsServerFactoryBean svrFactory1 = new JaxWsServerFactoryBean();
    svrFactory1.setServiceClass(HelloWorld.class);
    svrFactory1.setAddress("http://192.168.56.1:9000/HelloWorld");
    svrFactory1.setServiceBean(implementor);
    org.apache.cxf.endpoint.Server server1 = svrFactory1.create();
    server1.start();
    
  4. 客户端:

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setAddress("http://192.168.56.1:9000/HelloWorld");
    HelloWorld client = factory.create(HelloWorld.class);
    Message msg = new MessageImpl();
    msg.setId("abc");
    client.send(msg);
    
  5. 运行时收到错误如下:

    Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:160)
    at com.sun.proxy.$Proxy37.sayHiToUser(Unknown Source)
    at objecttype.Client.main(Client.java:60)
    
    
    Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
    .......
    

    如何更正此错误?

    此致

0 个答案:

没有答案