Home  >  Article  >  Java  >  How to call webservice interface

How to call webservice interface

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-06-30 13:44:5419885browse

调用方法:首先选中“项目”选项卡,点击鼠标右键,在弹出的右键菜单中选择“new”-“other”,接着找到“web service client”,点击“next”,在“wsdl url”输入接口地址,最后点击“next”,生成类文件即可。

How to call webservice interface

本教程操作环境:windows7系统、java10版、DELL G3电脑。

一、开发webservice接口的方式

1、jdk开发。

2、使用第三方工具开发,如cxf、shiro等等。

我这边介绍jdk方式webservice接口调用。

二、使用jdk调用webservice接口

1、选中项目 -> 右键 -> new -> othert -> 找到web service client 打开-> next -> 在wsdl url 输入 接口地址(格式:http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?wsdl) -> next.... -> 生成类文件。

 生成类文件就完成了。

2、调用过程:

package ww;

import java.util.List;

import cc.ArrayOfString;
import cc.TranslatorWebService;
import cc.TranslatorWebServiceSoap;

public class cccd {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        TranslatorWebServiceSoap as =  new TranslatorWebService().getTranslatorWebServiceSoap();
        String aw = as.helloWebXml();
        System.out.println(aw);
        List<String> ss = as.getEnCnTwoWayTranslator("dog").getString();
        System.out.println(ss.toString());
    }

}

结果:

或则用cmd命名得到 

wsimport -s G:\\workspace\\webService\\TheClient\\src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl

三、杂谈:

A:关于jax-ws、jax-rs的区别

    JAX-WS是针对WebService。而JAX-RS是针对RESTful HTTP Service。

    可以说这是两种风格的SOA架构风格:

    前者以动词为中心,指定的是每次执行函数,大力支持的厂商如BEA,IBM,MS基本都是开发工具厂商,没有开发工具来做WebService简直不是人干的活,呵呵)

    后者以名词为中心,每次执行的时候指的是资源,大力支持的厂商如Google,Yahoo,亚马孙等都是服务运营厂商,实在是REST简洁好用,又能满足绝大部分需求)。

    JAX-WS是面向消息的,每次请求的时候指定了请求的方法。JAX-RS是面向资源的。后则将网络上的东西当做一种资源,每次请求都是对该资源进行操作,比如对资源的增删查改。

    在网上看到这么一句话:JAVA 中共有三种WebService 规范,分别是JAXM&SAAJ、JAX-WS(JAX-RPC)、JAX-RS

相关视频教程推荐:Java视频教程

The above is the detailed content of How to call webservice interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn