CXF生成客户端

记录一下


下载CXF:apache-cxf-3.1.9.zip

http://cxf.apache.org/download.html


解压放在任意目录,设置环境变量CXF_HOME


然后把%CXF_HOME%/bin放到Path


设置的JDK版本为1.8:(JDK版本切换时,需要重新开启cmd)



cmd里面执行

C:\Users\Administrator>wsdl2java -d E:\\zone\\WSDL2Java\\source -client http://10.70.136.11:9080/test/api/GetPerson?wsdl


-d为存放目录


另:在生成客户端后,运行时出现如下错误:

Caused by: java.lang.RuntimeException: Could not find conduit initiator for address: http://127.0.0.1:9080/test/api/GetPwd and transport: http://schemas.xmlsoap.org/soap/http
	at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:224)
	at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:229)
	at org.apache.cxf.endpoint.AbstractConduitSelector.createConduit(AbstractConduitSelector.java:145)
	at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:107)
	at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63)
	at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:849)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:509)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:137)
	... 31 more


此时少引用了一个JAR造成的(当时第二个JAR没有引用进去),

<!-- apache cxf -->
		<dependency>
		    <groupId>org.apache.cxf</groupId>
		    <artifactId>cxf-rt-frontend-jaxws</artifactId>
		    <version>3.0.0</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.cxf</groupId>
		    <artifactId>cxf-rt-transports-http-jetty</artifactId>
		    <version>3.0.0</version>
		</dependency>

也是醉了。。。。


生成异步的客户端

wsdl2java -ant -client -d E:\\zone\\WSDL2Java\\source -b E:\\zone\\WSDL2Java\\async_binding.xml http://192.168.165.62:9086/msscpmis/xservices/FindUserService?wsdl

async_binding.xml文件的内容:

<bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          wsdlLocation="http://192.168.165.62:9086/msscpmis/xservices/FindUserService?wsdl"
          xmlns="http://java.sun.com/xml/ns/jaxws">
  <bindings node="wsdl:definitions">
    <enableAsyncMapping>true</enableAsyncMapping>
  </bindings>
</bindings>

异步的参考文献:

http://cxf.apache.org/docs/developing-a-consumer.html

猜你喜欢

转载自blog.csdn.net/xiazou/article/details/53671086