cxf 生成客户端

1. myeclipse -> new --> other --> web service client --> next 输入项目名 --> next 输入wsdl地址 -> finish


2 创建一个ApiClientTest 代码


import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
public class clientTest {

 public static void main(String[] args) {
        //调用WebService
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(IHelloWorldService.class);
         factory.setAddress("http://localhost:9090/helloWorld");
        
        IHelloWorldService service = (IHelloWorldService) factory.create();
        System.out.println("[result]" + service.sayHello("hoojo"));
    }

}


遇到异常

1:javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing

解决办法:传入参数类中有NULL值,确保参数赋值了或者赋值空字符串


2 org.apache.cxf.interceptor.Fault: Cannot write part parameters. RPC/Literal

传入一个NULL 做参数

你可能感兴趣的:(cxf 生成客户端)