1.在浏览器中打开webservice url,保存wsdl文件,如ContentService.xml
2.通过cxf命令“wsdl2java –d E:/file –frontend jaxws21 –client C:\ ContentService.xml”生成客户端代码
3.若报WSDLToJava Error: Thrown by JAXB : undefined simple or complex type 'soap-enc:Array' ,
则需要在生成的文件中找到
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />,
在浏览器中打开http://schemas.xmlsoap.org/soap/encoding/,
保存文件soap-encoding.xsd,
然后修改成<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soap-encoding.xsd"/>,
2.通过cxf命令“wsdl2java –d E:/file –frontend jaxws21 –client C:\ ContentService.xml”生成客户端代码
3.若报WSDLToJava Error: Thrown by JAXB : undefined simple or complex type 'soap-enc:Array' ,
则需要在生成的文件中找到
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />,
在浏览器中打开http://schemas.xmlsoap.org/soap/encoding/,
保存文件soap-encoding.xsd,
然后修改成<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soap-encoding.xsd"/>,
再运行上面的命令即可。
4.如果需要NTLM认证,则需在代码中加入如下的代码:
- Client client = ClientProxy.getClient(port);
- HTTPConduit http = (HTTPConduit) client.getConduit();
- HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
- httpClientPolicy.setConnectionTimeout(36000);
- httpClientPolicy.setAllowChunking(false);
- http.setClient(httpClientPolicy);
- http.getAuthorization().setAuthorizationType("NTLM");
- http.getAuthorization().setUserName("xxxx");
- http.getAuthorization().setPassword("xxxxx");