Soap 基於的Web Service在演化,實現其的技術棧也在隨之變化。Java領域出現了許多了Web Service相關的技術,從早期的Apache Axis,xfire到今天的Apache Axis2, Apache CXF, Metro,Spring WS。Java對Soap Web Service在早期提出了JAX-RPC的模型,今天JAX-RPC則被JAX-WS代替,這也體現了業界正在由RPC風格到 Document(Message)風格的轉變。
正如Axis官方所說,Axis雖然如今已經逐步被新一代的Web Service技術取代,但是寶刀未老,有時後還是得使用Axis
- 需要使用JAX-RPC的項目。只有兩個主要的JAX-RPC實現,一個是Sun給出的標準參考實現,另一個就是Axis
- 需要訪問或者發佈使用SOAP encoding的Web Service的項目,雖然SOAP encoding已經被廢棄,新一代的Web Service框架也不再支持這種use,但是也許項目需要接入的Web Service就是用了SOAP encoding的已經基於Axis構建的項目。如果用新一代的Web Service技術重寫已有的項目,投資回報堪憂,那估計還是繼續用Axis好些。
訪問已有的基於rpc/encoded的Web Service是一個比較常見的應用集成場景,尤其是在企業內部的信息交換,如果有跨平臺的Service實現存在,這種需求可能更加常見。
Maven依賴
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
Maven 插件
MojoHaus Maven 插件項目提供了一個支持Axis wdsl2java/java2wsdl 工具的插件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources</sourceDirectory>
<packageSpace>top.ourway.wsdl</packageSpace>
<subPackageByFileName>true</subPackageByFileName>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
利用其在項目構建生命週期中的代碼生成功能,可以很容實現對rpc/encorded服務的訪問,使用上和JAX-WS用wsimport工具生成代碼相比差不多,所生成代碼的使用模式也比較類似。
HelloServerPortType portType = new HelloServiceLocator().getHelloServerPort();
portType.sayHello("li mei");