1,先学习部署环境。建立Axis2周围环境。 http://blog.csdn.net/lanqibaoer/article/details/22731291

如今调用一个现有的公共webservice接口,http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?op=TranslatorString

调用方法:

 TranslatorString  输入中文,翻译成 拼音、英文。
參数:wordKey(中文)

如今要做,翻译词:【随便】。代码例如以下:

package cn.com.webxml;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient; public class Test {
public static void main(String[] args) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = new Options(); options.setAction("http://WebXml.com.cn/TranslatorString"); //由于soap1.2规范必须指定action
EndpointReference targetEPR = new EndpointReference("http://fy.webxml.com.cn/webservices/EnglishChinese.asmx? WSDL");
options.setTo(targetEPR);
options.setTimeOutInMilliSeconds(6000000000L);//设置超时时间
options.setTransportInProtocol(Constants.TRANSPORT_HTTP); //传输协议
serviceClient.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"http://WebXml.com.cn/","");
OMElement method = fac.createOMElement("TranslatorString ", omNs);
OMElement wordKey = fac.createOMElement("wordKey",omNs);
wordKey.setText("随便");
method.addChild(wordKey);
method.build();
OMElement result = serviceClient.sendReceive(method);
System.out.println(getResults(result));
System.exit(0);
}
/***
* 解析XML,将获取到的数据封装到list中
* @param element
* @return
*/
public static List<String> getResults(OMElement element) {
if (element == null) {
return null;
}
Iterator iterator = element.getChildElements();
Iterator innerItr;
List<String> list = new ArrayList<String>();
OMElement result = null;
while (iterator.hasNext()) {
result = (OMElement) iterator.next();
innerItr = result.getChildElements();
while(innerItr.hasNext()){
OMElement result2 = (OMElement)innerItr.next();
if(result2!=null){
String text = result2.getText();
if(text!=null && !("").equals(text)){
list.add(text);
}
}
}
}
return list;
}
}

执行结果:

注意:

 

版权声明:本文博主原创文章,博客,未经同意不得转载。

Axis2 转让Webservice 介面的更多相关文章

  1. axis2开发webservice程序

    一.环境 eclipse + jdk 6.0 + win7 64位 +tomcat7.0 二.创建服务端程序 1.新建web项目,webserviceTest 2.下载axis2,将lib目录下的ja ...

  2. Java借助axis2发布WebService

    Webservice: 1.Xml: 2.WSDL: Web service描述语言(WSDL)就是这样一个基于XML(标准通用标记语言下的一个子集)的语言,用于描述Web service及其函数.参 ...

  3. 使用Axis2实现WebService的发布和调用

    一.Axis2的下载和安装 1.可从http://ws.apache.org/axis2/ 下载Axis2的最新版本:      可以下载如下三个zip包: axis2-1.7.3-bin.zip(用 ...

  4. 使用Axis2编写webservice客户端,服务端

    1.编写客户端 Axis2开发WebService客户端 的3种方式 [参考帖子] http://blog.csdn.net/wangjinwei6912/article/details/851259 ...

  5. 用AXIS2发布WebService的方法

    Axis2+tomcat6.0 实现webService 服务端发布与客户端的调用. 第一步:首先要下载开发所需要的jar包 下载:axis2-1.6.1-war.zip http://www.apa ...

  6. axis2之webservice

    Axis2之webservice超详细教程 Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的 ...

  7. Axis2创建WebService服务端接口+SoupUI以及Client端demo测试调用

    第一步:引入axis2相关jar包,如果是pom项目,直接在pom文件中引入依赖就好 <dependency> <groupId>org.apache.axis2</gr ...

  8. Axis2开发WebService客户端 的3种方式

    Axis2开发WebService客户端 的3种方式 在dos命令下   wsdl2java        -uri    wsdl的地址(网络上或者本地)   -p  com.whir.ezoffi ...

  9. 转载 使用axis2构建webservice

    axis2是可以实现webservice的一个插件,使用这个插件可以发布webservice 1:可以使用这个插件来发布webservice,可以看网址:http://clq9761.iteye.co ...

随机推荐

  1. java线程学生进实训室

    Instructor: Dr. Simina FlutureCSCI 34 CSCI 34 CSCI 34CSCI 34 0 Summer 201 ummer 201 ummer 201ummer 2 ...

  2. 通达OA 新旧两种数据库连接方式

    老的连接方式: include_once("/inc/conn.php"); $cursor = exequery($connection,$query); 新的连接方式: inc ...

  3. 用数据说话,外贸产品选择(中篇)-google趋势分析法

    在上篇文章<用数据说话,贸B2C产品选择(上篇)-热门搜索法>中我们能搜索出来几种产品了,那我们就拿上次搜索出来的热门产品来做一个趋势分析.我们经过几个站点挑出了几种热卖产品Wedding ...

  4. 【HTML+CSS】(1)基本语法

    HTML基金会 <em>他强调标签,<strong>加粗标签 <q>短文本引用.<blockquote>长文本引用,这两个标签会让文字带双引號.   空 ...

  5. Word001

    C# Word 类库 2009-08-06 22:10 13470人阅读 评论(10) 收藏 举报 c#objectstring文档microsoftexcel using System;using ...

  6. JS判断用户连续输入

    方案1 // // $('#element').donetyping(callback[, timeout=1000]) // Fires callback when a user has finis ...

  7. DiskFileUpload类

    1.2.2 DiskFileUpload类 DiskFileUpload类是Apache文件上传组件的核心类,应用程序开发者通过这个类来与Apache文件上传组件进行交互.以下介绍DiskFileUp ...

  8. HBase系列文章汇总

    本文整理汇总了本博客自去年学习HBase以来写的全部关于HBase的相关内容.持续更新中,很多其它内容.敬请关注! 相关知识: 1.<布隆过滤器(Bloom Filter)> 2.< ...

  9. 玩转Web之Json(二)----jquery easy ui + Ajax +Json+SQL实现前后台数据交互

    最近在学Json,在网上也找过一些资料,觉得有点乱,在这里,我以easy ui的登录界面为例来说一下怎样用Json实现前后台的数据交互 使用Json,首先需要导入一些jar包,这些资源可以在网上下载到 ...

  10. Uva 10131 Is Bigger Smarter? (LIS,打印路径)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=1072">链接:UVa 10131 题意: ...