JAVA使用AXIS2调用asp.net的WebService

要求:按对方的要求把一串XML传给对方,对方返回一串XML结果.

对方使用的环境为ASP.NET

下载AXIS2的1.6.2包:http://axis.apache.org/axis2/java/core/download.cgi

解压到D:/axis2-1.6.2目录    (目录按自己的系统更改)

在DOS下进入到D:/axis2-1.6.2/bin目录

根据wsdl文件描述,使用 wsdl2java.bat 工具生成调用代码

命令如下:wsdl2java.bat -uri  http://xxx.xxx.xxx:xxx/Services.asmx?wsdl

生成的两个class文件(ServicesCallbackHandler.java,ServicesStub.java)在D:/axis2-1.6.2/bin/src目录下面, 拷贝到你的项目中进行编译

编译前要把D:/axis2-1.6.2/lib目录下面的包拷贝到你的项目中

调用测试:
public class TestCollectShowInfo{
public static String getXml(){
//该XML格式按照对方要求而生成
StringBuffer buf = new StringBuffer();
buf.append("<?xml version='1.0' encoding='UTF-8'?>");
buf.append("<root>");
buf.append("<head>");
buf.append("<requestid>11111</requestid>");
buf.append("<username>11111</username> ");
buf.append("<password>11111</password>");
buf.append("</head>");
buf.append("<body>");
buf.append("<record productid=\"1002\" title=\"东莞医疗机构首现社会监督员\" url =\"www.baidu.com\" createtime =\"2008-11-12\" type=\"0\"/>");
buf.append("<record productid=\"1002\" title=\"78岁老太手术成功彻底结束\" url =\"www.baidu.com\" createtime =\"2008-11-11\" type=\"1\" />");
buf.append("</body>");
buf.append("</root>");
return buf.toString();
}

public static void main(String[] args){
try{
String uri = "http://xxx.xxx.xxx:xxx/Services.asmx";
ServicesStub stub = new ServicesStub(uri);
CollectShowInfo info = new CollectShowInfo();
info.setXmlstr(getXml());   // xmlstr是要传给WEBSERVICE的内容.本例子传的是一个XML串
CollectShowInfoResponse response = stub.CollectShowInfo(info);
System.out.println(response.getCollectShowInfoResult()); //输出返回的结果
}catch (Exception e){
e.printStackTrace();
}
}
}

注意:
CollectShowInfo及CollectShowInfoResponse两个CLASS是ServicesStub.java中的内部类.

转载于:https://my.oschina.net/zhxm/blog/86763

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值