調(diào)用方法:首先選中“項(xiàng)目”選項(xiàng)卡,點(diǎn)擊鼠標(biāo)右鍵,在彈出的右鍵菜單中選擇“new”-“other”,接著找到“web service client”,點(diǎn)擊“next”,在“wsdl url”輸入接口地址,最后點(diǎn)擊“next”,生成類文件即可。
本教程操作環(huán)境:windows7系統(tǒng)、java10版、DELL G3電腦。
一、開發(fā)webservice接口的方式
1、jdk開發(fā)。
2、使用第三方工具開發(fā),如cxf、shiro等等。
我這邊介紹jdk方式webservice接口調(diào)用。
二、使用jdk調(diào)用webservice接口
1、選中項(xiàng)目 -> 右鍵?-> new?-> othert?-> 找到web service client?打開-> next?-> 在wsdl url 輸入 接口地址(格式:http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?wsdl)?-> next....?-> 生成類文件。
?生成類文件就完成了。
2、調(diào)用過程:
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()); } }
結(jié)果:
或則用cmd命名得到?
wsimport -s G:\\workspace\\webService\\TheClient\\src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl
三、雜談:
A:關(guān)于jax-ws、jax-rs的區(qū)別
JAX-WS是針對(duì)WebService。而JAX-RS是針對(duì)RESTful HTTP Service。
可以說這是兩種風(fēng)格的SOA架構(gòu)風(fēng)格:
前者以動(dòng)詞為中心,指定的是每次執(zhí)行函數(shù),大力支持的廠商如BEA,IBM,MS基本都是開發(fā)工具廠商,沒有開發(fā)工具來做WebService簡直不是人干的活,呵呵)
后者以名詞為中心,每次執(zhí)行的時(shí)候指的是資源,大力支持的廠商如Google,Yahoo,亞馬孫等都是服務(wù)運(yùn)營廠商,實(shí)在是REST簡潔好用,又能滿足絕大部分需求)。
JAX-WS是面向消息的,每次請(qǐng)求的時(shí)候指定了請(qǐng)求的方法。JAX-RS是面向資源的。后則將網(wǎng)絡(luò)上的東西當(dāng)做一種資源,每次請(qǐng)求都是對(duì)該資源進(jìn)行操作,比如對(duì)資源的增刪查改。
在網(wǎng)上看到這么一句話:JAVA?中共有三種WebService?規(guī)范,分別是JAXM&SAAJ、JAX-WS(JAX-RPC)、JAX-RS
相關(guān)視頻教程推薦: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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)