使用axis调用webservice接口
以前使用webservice服务都很简单,就是根据提供的wsdl接口地址,通过eclipse或者idea自动生成webservice client包,然后直接调用就可以了。这次业务提供的wsdl是需要验证soapheader的,而且通过IDE工具无法生成可以直接调用的类包,无奈只能通过其他办法来实现,通过百度,可以使用axis包来实现,具体实现过程如下:
1、需要的jar包依赖
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency> <dependency>
<groupId>javax.xml.rpc</groupId>
<artifactId>javax.xml.rpc-api</artifactId>
<version>1.1.1</version>
</dependency> <dependency>
<groupId>org.apache.geronimo.bundles</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4_1</version>
</dependency> <dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
2、WSDL接口文档
<?xml version="1.0" encoding="utf-8"?> <wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://tempuri.org/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="SendXMLFile">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlProjectData" type="s:base64Binary"/>
<s:element minOccurs="0" maxOccurs="1" name="reportDate" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SendXMLFileResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SendXMLFileResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="UserSoapHeader" type="tns:UserSoapHeader"/>
<s:complexType name="UserSoapHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PassWord" type="s:string"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="SendXMLFileSoapIn">
<wsdl:part name="parameters" element="tns:SendXMLFile"/>
</wsdl:message>
<wsdl:message name="SendXMLFileSoapOut">
<wsdl:part name="parameters" element="tns:SendXMLFileResponse"/>
</wsdl:message>
<wsdl:message name="SendXMLFileUserSoapHeader">
<wsdl:part name="UserSoapHeader" element="tns:UserSoapHeader"/>
</wsdl:message>
<wsdl:portType name="DataReportServiceSoap">
<wsdl:operation name="SendXMLFile">
<wsdl:input message="tns:SendXMLFileSoapIn"/>
<wsdl:output message="tns:SendXMLFileSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DataReportServiceSoap" type="tns:DataReportServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SendXMLFile">
<soap:operation soapAction="http://tempuri.org/SendXMLFile" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:SendXMLFileUserSoapHeader" part="UserSoapHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="DataReportServiceSoap12" type="tns:DataReportServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SendXMLFile">
<soap12:operation soapAction="http://tempuri.org/SendXMLFile" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
<soap12:header message="tns:SendXMLFileUserSoapHeader" part="UserSoapHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DataReportService">
<wsdl:port name="DataReportServiceSoap" binding="tns:DataReportServiceSoap">
<soap:address location="http://221.226.63.54:8187/DataReportService.asmx"/>
</wsdl:port>
<wsdl:port name="DataReportServiceSoap12" binding="tns:DataReportServiceSoap12">
<soap12:address location="http://221.226.63.54:8187/DataReportService.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
3、接口调用代码
public static void sendReportTest(byte[] reportData, String date){
try {
// 服务端的url,需要根据情况更改。
String endpointURL = URL;
Service service = new Service();
Call call = (Call) service.createCall();
call.setTimeout(new Integer(60000));
call.setTargetEndpointAddress(new URL(endpointURL));
call.setSOAPActionURI("http://tempuri.org/SendXMLFile");
call.setOperationName(new QName("http://tempuri.org/","SendXMLFile"));// 设置操作的名称。
// 由于需要认证,故需要设置调用的用户名和密码。
SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://tempuri.org/", "UserSoapHeader");
soapHeaderElement.setNamespaceURI("http://tempuri.org/");
try {
soapHeaderElement.addChildElement("UserId").setValue(USER_ID);
soapHeaderElement.addChildElement("PassWord").setValue(PASSWORD);
} catch (SOAPException e) {
e.printStackTrace();
}
call.addHeader(soapHeaderElement);
call.setReturnType(XMLType.XSD_STRING);// 返回的数据类型
call.addParameter(new QName("http://tempuri.org/","xmlProjectData"), XMLType.XSD_BASE64, ParameterMode.IN);// 参数的类型
call.addParameter(new QName("http://tempuri.org/","reportDate"), XMLType.XSD_STRING, ParameterMode.IN);// 参数的类型
String result = (String) call.invoke(new Object[]{reportData,date});// 执行调用
// 结果信息解析
Document document = DocumentHelper.parseText(result);
Element rootElement = document.getRootElement();
Iterator iter = rootElement.elementIterator("State");
while(iter.hasNext()){
Element recordEle = (Element) iter.next();
String code = recordEle.getTextTrim();// State值
if("0".equals(code)){ //成功
Logger.getRootLogger().error("调用接口成功");
}else{ // 失败保存log
Logger.getRootLogger().error(result);
}
}
} catch (Exception e) {
Logger.getRootLogger().error("调用接口失败",e);
}
}使用axis调用webservice接口的更多相关文章
- 关于使用axis调用webservice接口方法
1.概述: 我们有时候会调用webserviec接口,我们向接口发送请求参数,从接口接收返回值. 2.形式: package client; import org.apache.axis.client ...
- 利用axis调用webservice接口
一.首先把wsdl文件放入eclipse中某个项目中的src目录下 二.右键弹出webservice,然后点击webservice菜单,选中genernator client ,选择axis生成Jav ...
- Java调用webservice接口方法
java调用webservice接口 webservice的 发布一般都是使用WSDL(web service descriptive langu ...
- 使用axis调用WebService服务端
由于项目中要调用其他公司的接口,研究了下axis调用webService这种方式,现将代码贴出,以备以后查阅: package com.xbq; import javax.xml.namespace. ...
- Java通过axis调用WebService
上午头给了我一个任务,让我对接别的公司的webservice接口,各种百度,看的头晕脑花的,终于通了,记录一下吧. jar包奉上,http://pan.baidu.com/s/1jSchC 包含:ax ...
- (转)Java通过axis调用WebService
转自:http://blog.csdn.net/wanglha/article/details/49679825 转载地址:http://www.linuxidc.com/Linux/2015-06/ ...
- php中创建和调用webservice接口示例
php中创建和调用webservice接口示例 这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...
- 使用soapui调用webservice接口
soapui是专门模拟调用webservice接口的工具,下面介绍下怎么使用: 1.下载soapui并安装: 2.以免费天气获取接口为例:http://www.webservicex.net/glob ...
- 使用JS调用WebService接口
<script> $(document).ready(function () { var username = "admin"; var password = &quo ...
随机推荐
- Python最新暴力破解WiFi,攻破所有密码限制,最强破解!
暴力破解wifi密码 这个代码也是非常简单,这里需要用Python中的pywifi这个库,所以需要在DOS命令下安装这个库,同样使用pip install pywifi,很简单就安装成功了,我用的是P ...
- Django 项目搭建
django(mvt结构) 虚拟环境 创建虚拟环境 mkvirtualenv django_py3 -p python3 切换虚拟环境 wokeon 虚拟环境名称 删除虚拟环境 rmvirtualen ...
- use matplotlib to draw scatter plot
There are many pionts in this kind of table. How to do it? We can use scatter() to draw it. Code: im ...
- 文本编辑器vim/vi——命令模式
一个完整的指令的标准格式: Linux通用的格式——#指令主体(空格) [选项](空格) [操作对象] 一个指令可以包含多个选项,操作对象也可以是多个. vim指令: 指令:vim (vim是一款 ...
- jquery快速常用技能
jQuery入口函数与js入口函数 (window.onload = function(){})的对比: 1.JavaScript的入口函数要等到页面中所有资源(包括图片.文件)加载完成才开始执行. ...
- 五十六、SAP中LVC表格的常用布局属性LVC_S_LAYO
一.LVC_S_LAYO为表格常用的布局属性,包括网格线,宽度自适应,隐藏主键等 二.我们来对比使用前和使用后的表格,这个原始布局风格的表格 三.这个是设置了相关属性的表格
- 洛谷 P2747 Canada Tour 周游加拿大 动态规划
Description 你赢得了一场航空公司举办的比赛,奖品是一张加拿大机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行,直到你到达最东边的城市,再由东向西返回,直到你回到开始的城 ...
- you-get加ffmpeg获取视频素材并转格式
最近做视频,觉得素材不好下载,下载了转格式又很麻烦,终于,在网上ob了很久的我找到了属于自己的工具. you-get视频下载 当你在网上找视频素材的时候发现了一个自己觉得很有意思的视频,但是获取这个视 ...
- 实验吧-隐写术-男神一般都很低调很低调的!!(stegsolve->Image Combiner + DES加密)
先介绍一下DES加密:(也可参考https://blog.csdn.net/zz_Caleb/article/details/87016017,第14个) 1)对称加密,参考:对称加密和非对称加密 2 ...
- js 琐碎
1.setTimeout() .setInterval() setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式.(即n毫秒后执行一次) setTimeout(code,n) set ...