WebService是一种跨编程语言、跨操作系统平台的远程调用技术,已存在很多年了,很多接口也都是通过WebService方式来发布的;本系列文章主要介绍Java调用WebService的各种方法,使用在线的中文简体字<->繁体字转换服务(http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx)作为测试服务端,使用其中的简体字转换为繁体字方法toTraditionalChinese来演示WebService的调用。本文主要做些准备工作,方便后续文章中实际的调用。

1、WSDL

为了防止该在线WebService不可用,这里把WSDL贴在这里,方便与代码对照。

http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://webxml.com.cn/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webxml.com.cn/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a> <strong>中文简体字<->繁体字转换 WEB 服务</strong><br />此中文简体字<->繁体字转换Web Services请不要用于任何商业目的,若有需要请<a href="http://www.webxml.com.cn/zh_cn/contact_us.aspx" target="_blank">联系我们</a>,欢迎技术交流。 QQ:8409035<br /><strong>使用本站 WEB 服务请注明或链接本站:http://www.webxml.com.cn/ 感谢大家的支持</strong>!<br /><br />&nbsp;
</wsdl:documentation>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://webxml.com.cn/">
<s:element name="toSimplifiedChinese">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="sText" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="toSimplifiedChineseResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="toSimplifiedChineseResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="toTraditionalChinese">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="sText" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="toTraditionalChineseResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="toTraditionalChineseResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string"/>
</s:schema>
</wsdl:types>
<wsdl:message name="toSimplifiedChineseSoapIn">
<wsdl:part name="parameters" element="tns:toSimplifiedChinese"/>
</wsdl:message>
<wsdl:message name="toSimplifiedChineseSoapOut">
<wsdl:part name="parameters" element="tns:toSimplifiedChineseResponse"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseSoapIn">
<wsdl:part name="parameters" element="tns:toTraditionalChinese"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseSoapOut">
<wsdl:part name="parameters" element="tns:toTraditionalChineseResponse"/>
</wsdl:message>
<wsdl:message name="toSimplifiedChineseHttpGetIn">
<wsdl:part name="sText" type="s:string"/>
</wsdl:message>
<wsdl:message name="toSimplifiedChineseHttpGetOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseHttpGetIn">
<wsdl:part name="sText" type="s:string"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseHttpGetOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:message name="toSimplifiedChineseHttpPostIn">
<wsdl:part name="sText" type="s:string"/>
</wsdl:message>
<wsdl:message name="toSimplifiedChineseHttpPostOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseHttpPostIn">
<wsdl:part name="sText" type="s:string"/>
</wsdl:message>
<wsdl:message name="toTraditionalChineseHttpPostOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:portType name="TraditionalSimplifiedWebServiceSoap">
<wsdl:operation name="toSimplifiedChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>繁体字转换为简体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toSimplifiedChineseSoapIn"/>
<wsdl:output message="tns:toSimplifiedChineseSoapOut"/>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>简体字转换为繁体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toTraditionalChineseSoapIn"/>
<wsdl:output message="tns:toTraditionalChineseSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TraditionalSimplifiedWebServiceHttpGet">
<wsdl:operation name="toSimplifiedChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>繁体字转换为简体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toSimplifiedChineseHttpGetIn"/>
<wsdl:output message="tns:toSimplifiedChineseHttpGetOut"/>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>简体字转换为繁体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toTraditionalChineseHttpGetIn"/>
<wsdl:output message="tns:toTraditionalChineseHttpGetOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TraditionalSimplifiedWebServiceHttpPost">
<wsdl:operation name="toSimplifiedChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>繁体字转换为简体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toSimplifiedChineseHttpPostIn"/>
<wsdl:output message="tns:toSimplifiedChineseHttpPostOut"/>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<br /><h3>简体字转换为繁体字</h3><p>输入参数:sText = 字符串; 返回数据:字符串。</p><br />
</wsdl:documentation>
<wsdl:input message="tns:toTraditionalChineseHttpPostIn"/>
<wsdl:output message="tns:toTraditionalChineseHttpPostOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TraditionalSimplifiedWebServiceSoap" type="tns:TraditionalSimplifiedWebServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="toSimplifiedChinese">
<soap:operation soapAction="http://webxml.com.cn/toSimplifiedChinese" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<soap:operation soapAction="http://webxml.com.cn/toTraditionalChinese" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TraditionalSimplifiedWebServiceSoap12" type="tns:TraditionalSimplifiedWebServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="toSimplifiedChinese">
<soap12:operation soapAction="http://webxml.com.cn/toSimplifiedChinese" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<soap12:operation soapAction="http://webxml.com.cn/toTraditionalChinese" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TraditionalSimplifiedWebServiceHttpGet" type="tns:TraditionalSimplifiedWebServiceHttpGet">
<http:binding verb="GET"/>
<wsdl:operation name="toSimplifiedChinese">
<http:operation location="/toSimplifiedChinese"/>
<wsdl:input>
<http:urlEncoded/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<http:operation location="/toTraditionalChinese"/>
<wsdl:input>
<http:urlEncoded/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TraditionalSimplifiedWebServiceHttpPost" type="tns:TraditionalSimplifiedWebServiceHttpPost">
<http:binding verb="POST"/>
<wsdl:operation name="toSimplifiedChinese">
<http:operation location="/toSimplifiedChinese"/>
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded"/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="toTraditionalChinese">
<http:operation location="/toTraditionalChinese"/>
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded"/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TraditionalSimplifiedWebService">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a> <strong>中文简体字<->繁体字转换 WEB 服务</strong><br />此中文简体字<->繁体字转换Web Services请不要用于任何商业目的,若有需要请<a href="http://www.webxml.com.cn/zh_cn/contact_us.aspx" target="_blank">联系我们</a>,欢迎技术交流。 QQ:8409035<br /><strong>使用本站 WEB 服务请注明或链接本站:http://www.webxml.com.cn/ 感谢大家的支持</strong>!<br /><br />&nbsp;
</wsdl:documentation>
<wsdl:port name="TraditionalSimplifiedWebServiceSoap" binding="tns:TraditionalSimplifiedWebServiceSoap">
<soap:address location="http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx"/>
</wsdl:port>
<wsdl:port name="TraditionalSimplifiedWebServiceSoap12" binding="tns:TraditionalSimplifiedWebServiceSoap12">
<soap12:address location="http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx"/>
</wsdl:port>
<wsdl:port name="TraditionalSimplifiedWebServiceHttpGet" binding="tns:TraditionalSimplifiedWebServiceHttpGet">
<http:address location="http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx"/>
</wsdl:port>
<wsdl:port name="TraditionalSimplifiedWebServiceHttpPost" binding="tns:TraditionalSimplifiedWebServiceHttpPost">
<http:address location="http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

2、用SoapUI生成Soap消息

该在线WebService同时实现Soap1.1和Soap1.2,这里分别生成消息。

2.1、Soap1.1

查询xml

查看Raw

2.1、Soap1.2

查看xml

查看Raw

3、本地WebService服务

由于我们用的在线WebService服务端为.NET实现的,而我们客户端是JAVA,如果是RPC方式调用则无法调用;这里创建一个本地的JAX-WS实现的WebService,用于这个系列文章中RPC方式的调用。RPC已经过时,但为了技术的完整性,也记录下。

3.1、接口类

package com.inspur.zsyw.ws;

import javax.jws.WebParam;
import javax.jws.WebService; @WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface ITestService {
String hello(@WebParam(name = "name") String name);
}

3.1、实现类

package com.inspur.zsyw.ws.impl;

import com.inspur.zsyw.ws.ITestService;

@javax.jws.WebService(endpointInterface="com.inspur.zsyw.ws.ITestService", targetNamespace = "http://ws.zsyw.inspur.com/", serviceName = "TestService")
public class TestServiceImpl implements ITestService {
@Override
public String hello(String name) {
return "hello," + name;
}
}

3.3、本地WSDL

http://10.40.103.48:9006/zsywservice/TestService?wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5.
-->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.zsyw.inspur.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.zsyw.inspur.com/" name="TestService">
<types/>
<message name="hello">
<part name="name" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="ITestService">
<operation name="hello">
<input message="tns:hello"/>
<output message="tns:helloResponse"/>
</operation>
</portType>
<binding name="TestServiceImplPortBinding" type="tns:ITestService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://ws.zsyw.inspur.com/"/>
</input>
<output>
<soap:body use="literal" namespace="http://ws.zsyw.inspur.com/"/>
</output>
</operation>
</binding>
<service name="TestService">
<port name="TestServiceImplPort" binding="tns:TestServiceImplPortBinding">
<soap:address location="http://10.40.103.48:9006/zsywservice/TestService"/>
</port>
</service>
</definitions>

4、调用

本文主要介绍一些准备工作,具体调用参见下列文章:

Java调用WebService方法总结(2)--JAX-WS调用WebService

Java调用WebService方法总结(3)--wsimport调用WebService

Java调用WebService方法总结(4)--Axis调用WebService

Java调用WebService方法总结(5)--Axis2调用WebService

Java调用WebService方法总结(6)--XFire调用WebService

Java调用WebService方法总结(7)--CXF调用WebService

Java调用WebService方法总结(8)--soap.jar调用WebService

Java调用WebService方法总结(9,end)--Http方式调用WebService

Java调用WebService方法总结(1)--准备工作的更多相关文章

  1. Java调用WebService方法总结(9,end)--Http方式调用WebService

    Http方式调用WebService,直接发送soap消息到服务端,然后自己解析服务端返回的结果,这种方式比较简单粗暴,也很好用:soap消息可以通过SoapUI来生成,也很方便.文中所使用到的软件版 ...

  2. Java调用WebService方法总结(8)--soap.jar调用WebService

    Apache的soap.jar是一种历史很久远的WebService技术,大概是2001年左右的技术,所需soap.jar可以在http://archive.apache.org/dist/ws/so ...

  3. Java调用WebService方法总结(7)--CXF调用WebService

    CXF = Celtix + XFire,继承了Celtix和XFire两大开源项目的精华,是一个开源的,全功能的,容易使用的WebService框架.文中所使用到的软件版本:Java 1.8.0_1 ...

  4. Java调用WebService方法总结(6)--XFire调用WebService

    XFire是codeHaus组织提供的一个WebService开源框架,目前已被Apache的CXF所取代,已很少有人用了,这里简单记录下其调用WebService使用方法.官网现已不提供下载,可以到 ...

  5. Java调用WebService方法总结(5)--Axis2调用WebService

    Axis2是新一点Axis,基于新的体系结构进行了全新编写,有更强的灵活性并可扩展到新的体系结构.文中demo所使用到的软件版本:Java 1.8.0_191.Axis2 1.7.9. 1.准备 参考 ...

  6. Java调用WebService方法总结(4)--Axis调用WebService

    Axis是比较常用的WebService框架,该项目在2006实现了最终版,后面就没有更新了.文中demo所使用到的软件版本:Java 1.8.0_191.Axis 1.4. 1.准备 参考Java调 ...

  7. Java调用WebService方法总结(3)--wsimport调用WebService

    wsimport是JDK自带的把WSDL转成Java的工具,可以很方便的生成调用WebService的代码.文中所使用到的软件版本:Java 1.8.0_191. 1.准备 参考Java调用WebSe ...

  8. Java调用WebService方法总结(2)--JAX-WS调用WebService

    用JAX-WS(Java API for XML Web Services)调用WebService不需要引入其他框架,都是JDK自带的:文中所使用到的软件版本:Java 1.8.0_191.Dom4 ...

  9. java调用webservice方法

    由于项目的历史原因,webservice服务端是乙方公司开发的,我们自己开发的系统需要去调用乙方公司的webservice接口.前面用了网上提供的一种方法(非生成代理类),怎么也调用不成功(也许是因为 ...

随机推荐

  1. php7 yum安装

    CentOs 7.X: rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.we ...

  2. 还在用难用的AssetBundle?快来运用Unity新的可寻址资源系统,助力游戏开发

    Unity Addressables可寻址资源系统是一个强大的Unity资源包,它能够帮助解决游戏开发中最重要的一些挑战:高效率和轻松的内容管理. 在管理游戏资源时,往往很难维持好的标准,从而避免让项 ...

  3. Java实现Txt转PDF文件

    TxT转PDF可以直接使用IText就可以了,IText在pdf领域可以说暂时是最好的方案了.通过直接读取txt文件,然后生成pdf,再添加文本就可以了. 代码如下: public class Txt ...

  4. Springboot单元测试Junit深度实践

    Springboot单元测试Junit深度实践 前言 单元测试的好处估计大家也都知道了,但是大家可以发现在国内IT公司中真正推行单测的很少很少,一些大厂大部分也只是在核心产品推广单测来保障质量,今天这 ...

  5. dubbo、zookeeper心跳相关参数解析与测试

    dubbo consumer和provider的心跳机制 dubbo客户端和dubbo服务端之间存在心跳,目的是维持provider和consumer之间的长连接.由dubbo客户端主动发起,可参见d ...

  6. implement a list using Rust

    Rust果然比較複雜,在經歷了n次compile fail,終于寫成了一個 list 難點: 對Rc<>的用法不熟悉.對borrow checker不夠熟悉 有些寫法可能還不是最短的 us ...

  7. 【NumPy】 之常见运算(np.around、np.floor、np.ceil、np.where)

    aroundnp.around 返回四舍五入后的值,可指定精度. around(a, decimals=0, out=None) a 输入数组 decimals 要舍入的小数位数. 默认值为0. 如果 ...

  8. centos7 docker swarm加入集群失败

    提示的错误为 [root@localhost downloads]# docker swarm join --token SWMTKN-1-2ezr0k5ybds1la4vgi2z7j8ykxkmm0 ...

  9. EasyNVR网页无插件播放摄像机RTSP流是如何调取接口在Web页实现多窗口同时直播的

    背景需求 在互联网飞速发展的时代,开发者常会说的一个词就是"跨平台".自从移动端的用户需求越来越大,H5逐渐发展,跨平台似乎已经成为了软件开发不可或缺的技术.EasyNVR互联网直 ...

  10. EasyRTMP推送扩展支持HEVC(H265) RTMP推送之Metadata结构填写详解

    我们在<EasyNVR摄像机网页直播中,推流组件EasyRTMP推送RTMP扩展支持HEVC(H.265)的方案>中描述了关于EasyRTMP进行RTMP HEVC(H.265)推流的概括 ...