Java6 WebService学习
参考了网络上中资料,自己学习实践了一个Java6 WebService.
首先,建立一个WebService:
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class MyJ6WebService {
public String SayHello(String strName) {
return "Hello ,"+strName+"!";
}
public static void main(String[] args) {
//发布WebService,注意如果提示:Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Address already in use: bind
//则需要修改一下发布端口
Endpoint.publish("http://localhost:8030/garfield.MyJ6WebService", new MyJ6WebService());
System.out.println("WebService was published success !");
}
}
启动Tomcat,然后运行,系统会输出:WebService was published success !,表示WebService已启动。
可以在浏览器中输入地址:http://localhost:8030/garfield.MyJ6WebService?wsdl
显示WebService信息:
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01.
-->
- <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://garfield/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://garfield/" name="MyJ6WebServiceService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://garfield/" schemaLocation="http://localhost:8030/garfield.MyJ6WebService?xsd=1" />
</xsd:schema>
</types>
- <message name="SayHello">
<part name="parameters" element="tns:SayHello" />
</message>
+ <message name="SayHelloResponse">
<part name="parameters" element="tns:SayHelloResponse" />
</message>
- <portType name="MyJ6WebService">
- <operation name="SayHello">
<input wsam:Action="http://garfield/MyJ6WebService/SayHelloRequest" message="tns:SayHello" />
<output wsam:Action="http://garfield/MyJ6WebService/SayHelloResponse" message="tns:SayHelloResponse" />
</operation>
</portType>
- <binding name="MyJ6WebServicePortBinding" type="tns:MyJ6WebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="SayHello">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="MyJ6WebServiceService">
- <port name="MyJ6WebServicePort" binding="tns:MyJ6WebServicePortBinding">
<soap:address location="http://localhost:8030/garfield.MyJ6WebService" />
</port>
</service>
</definitions>
在WebService启动的状态下,在命令行中输入:
ield.MyJ6WebService?wsdl
parsing WSDL...
generating code...
compiling code...
E:\Temp>
注意,一定要对应你发布的WebService信息!
然后系统会自动生成相关的接口文件,如下:
新建Java工程,将输出文件引入,然后建立测试类:
import garfield.garfieldj6wsclient.*;
public class WebClient {
/**
* @param args
*/
public static void main(String[] args) {
//创建一个客户端服务对象
MyJ6WebService myJ6WS = new MyJ6WebServiceService().getMyJ6WebServicePort();
//调用服务方法,并得到方法返回值
String strTest = myJ6WS.sayHello("Garfield");
//打印服务的返回值
System.out.println(strTest);
}
}
在WebService运行情况下,运行客户端测试程序,输出:
Hello ,Garfield!
转载于:https://www.cnblogs.com/GarfieldTom/archive/2012/09/14/2684361.html
Java6 WebService学习相关推荐
- [WebService] xml WebService学习1
[WebService] xml WebService学习1 管理工具->性能 SQL 事件探查器可以使您轻松地捕获在正常负载下服务器上发生的所有事件,并提供有关这些事件的信息.将 SQL 事件 ...
- webService学习9:jquery ajax调用webservice
1 参照 webService学习7:调用天气接口 生成客户端代码 2 前台代码 <%@ page language="java" import="java.ut ...
- webService学习4:客户端调用服务端的代码
1 服务器端sayHello变化了一点,代码如下 @WebService public class HelloWSImpl implements HelloWS {public String sayH ...
- webservice学习01:wsdl文档结构
webservice学习01:wsdl文档结构 wsdl文档结构 WSDL文档示例 <wsdl:definitions xmlns:xsd="http://www.w3.org/200 ...
- WebService学习总结(三)——使用JDK开发WebService
一.WebService的开发手段 使用Java开发WebService时可以使用以下两种开发手段 1. 使用JDK开发(1.6及以上版本) 2.使用CXF框架开发(工作中) 二.使用JDK开发Web ...
- WebService学习:SOPA与WSDL基本语法 .
在WebService学习中,发现SOPA和WSDL的语法比较繁琐,故将以下几点记下,以备查看. SOPA基本语法: SOAP消息基于XML文档构建,一条SOAP消息就是一份特定的XML文档,SOAP ...
- WebService学习:SOPA与WSDL基本语法
转载自:http://blog.csdn.net/lissdy/article/details/8219659 在WebService学习中,发现SOPA和WSDL的语法比较繁琐,故将以下几点记下,以 ...
- WebService学习总结
本文出自 http://www.cnblogs.com/ 的 孤傲苍狼 原文网址: http://www.cnblogs.com/xdp-gacl/category/629559.html http: ...
- WebService学习心得
WebService学习心得01--webservice服务端及客户端开发 1.定义 Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交 ...
最新文章
- aws python sdk send sns_AWS:boto3订阅SNS时的空SQS队列
- python编程 入门到实践-终于懂了python编程从入门到实践
- 自定义 Spring Boot Starter
- java socket 远程调用_SpringBoot使用Netty实现远程调用的示例
- jzoj1882-亲戚【并查集】
- 【Pytorch神经网络实战案例】09 使用卷积提取图片的轮廓信息(手动模拟Sobel算子)
- python数据挖掘需要的库_python数据挖掘需要学的内容
- LeetCode刷题(47)--Gray Code
- eclipse版本号 备注
- indesign图片规定在左下角_InDesign如何为目录模板设置母版
- 算法竞赛入门经典(第二版) —— 第一章 程序设计入门
- 怎么提高公文写作水平?原来这就是公文写作通知类模板
- WPS Office 2020 for Mac(wps2020)3.8.0(6081)中文
- qq文件未上传至平台服务器,QQ传送离线文件慢是什么原因?原因及处理方法
- 训练好的神经网络 如何预测_【家长必看】如何帮助孩子训练好口才?
- 编写MTK6737平台的GPIO驱动例程(六)
- 软件工程之软件需求分析
- 电商用户价值分析——基于RFM模型、KMeans聚类
- 人民币对美元汇率中间价报6.7615元 下调73个基点
- C# winform PictureBox显示opencv Mat图片