Java通过Axis2调用WCF

一.在http://axis.apache.org/axis2/java/core/download.cgi下载axis2(1.6:http://apache.etoak.com//axis/axis2/java/core/1.6.1/axis2-1.6.1-bin.zip)

二.解压到你觉得应该解压的目录
然后进入bin,执行axis2server.sh启动测试服务器,如果看到以下信息,表示启动成功.

mrjs-MacBook-Pro:bin mrj$ ./axis2server.sh
Using AXIS2_HOME: /Users/mrj/Downloads/axis2-1.6.1
Using JAVA_HOME: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
[INFO] [SimpleAxisServer] Starting
[INFO] [SimpleAxisServer] Using the Axis2 Repository/Users/mrj/Downloads/axis2-1.6.1/repository
[SimpleAxisServer] Using the Axis2 Repository/Users/mrj/Downloads/axis2-1.6.1/repository
[SimpleAxisServer] Using the Axis2 Configuration File/Users/mrj/Downloads/axis2-1.6.1/conf/axis2.xml
[INFO] Clustering has been disabled
[INFO] Deploying module: addressing-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/addressing-1.6.1.mar
[INFO] Deploying module: metadataExchange-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/mex-1.6.1.mar
[INFO] Deploying module: mtompolicy-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/mtompolicy-1.6.1.mar
[INFO] Deploying module: ping-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/ping-1.6.1.mar
[INFO] Deploying module: script-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/scripting-1.6.1.mar
[INFO] Deploying module: soapmonitor-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/soapmonitor-1.6.1.mar
[INFO] Deploying Web service: version.aar - file:/Users/mrj/Downloads/axis2-1.6.1/repository/services/version.aar
[INFO] Listening on port 8080
[INFO] [SimpleAxisServer] Started
[SimpleAxisServer] Started


注:你可能需要给文件加上可执行的权限

sudo chmod a+rwx *


三.配置相应环境变量

    sudo vim /etc/profile



export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

export AXIS2_HOME=/Users/mrj/Downloads/axis2-1.6.1



source /etc/profile


四.使用wsdl生成java文件
进入axis2的bin目录(当然你可以配置环境变量)

如果你已将wsdl下载到本地:

./wsdl2java.sh -o javacode -uri /Users/mrj/Downloads/PadManage.xml


如果是一个web资源:

./wsdl2java.sh -o javacode -uri http://127.0.0.1:8080/axis2/services/Version?wsdl


注:-o指定文件生成目录,你还可以指定-r以生成单元测试类,关于更多的信息,请参数axis2帮助文档.

五.把生成的java文件目录copy到你的项目路径,刷新开发工具,此时你可以看到生成的java文件.
此时你可能会看到项目中有些错误,你只需要将下载来的axis2目录lib里面的jar包加入bulid path.

// -------------------------
附上对helloworld的单元测试
// -------------------------

package sample.axisversion.test;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.junit.Test;

import sample.axisversion.VersionExceptionException;
import sample.axisversion.VersionStub;
import sample.axisversion.VersionStub.GetVersion;

/**
*
* @author mrj
*
*/
public class TestHelloAsix {

@Test
public void testGetVersion() {
try {
VersionStub versionStup = new VersionStub();
GetVersion request = new GetVersion();

System.out.println(versionStup.getVersion(request).get_return());
} catch (AxisFault e) {
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (VersionExceptionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}



控制台输出:
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).
log4j:WARN Please initialize the log4j system properly.
Hi - the Axis2 version is 1.6.1


--------------------
同时jax-ws也是一个不错的东西,你可以在(http://jax-ws-commons.java.net/)下载到它的最新版本(JDK已经带了).
下面这条命令可以生成java代码

wsimport -s /Users/mrj/Desktop/ -extension -p mypkg http://192.168.1.100:8812/PadManage/?wsdl


可能需要用到的jar包:
webservices-rt.jar(**必须的一个)
-- helloworld程序不需要以下jar包,.
webservices-api.jar
webservices-extra-api.jar
webservices-extra.jar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值