1,建立自己的java项目my_service

2,建立包,com.hjg.service

3,创建类:

IMyService.java

package com.hjg.service;
import javax.jws.WebService; @WebService
public interface IMyService {
int add(int a, int b);
int minus(int a,int b);
}

加上@Webservice注解
JAX-WS注解,表示java api xml for webservice。JDK自带API的XML格式的webservice

MyServiceImpl.java

package com.hjg.service;
import javax.jws.WebService;
@WebService(endpointInterface="com.hjg.service.IMyService")
public class MyServiceImp implements IMyService {
@Override
public int add(int a, int b) {
System.out.println(a+"+"+b+" = "+(a+b));
return (a+b);
} @Override
public int minus(int a, int b) {
System.out.println(a+"*"+b+" = "+(a*b));
return (a*b);
}
}

endpointInterface指定接入点接口:接口必须存在

服务器端,MyService.java

package com.hjg.service;
import javax.xml.ws.Endpoint;
public class MyServer {
public static void main(String[] args) {
//访问方式:http://localhost:8888/ns?wsdl
String address = "http://localhost:8888/ns";
Endpoint.publish(address, new MyServiceImp());
}
}

客户端,MyClient.java

package com.hjg.service;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class MyClient {
public static void main(String[] args) {
try {
//服务WSDL Document的地址
URL url = new URL("http://localhost:8888/ns");
//Qnameqname是qualified name 的简写
//构成:由名字空间(namespace)前缀(prefix)以及冒号(:),还有一个元素名称构成
//由发布的wsdl可知namespace为http://service.hjg.com/,
QName sname = new QName("http://service.hjg.com/","MyServiceImpService");
Service service = Service.create(url, sname);
IMyService ms = service.getPort(IMyService.class);
int rs = ms.add(, );
System.out.println(rs); } catch (Exception e) {
e.printStackTrace();
}
}
}

浏览器访问http:localhost:8888/ns?wsdl 返回:

  <?xml version="1.0" encoding="UTF-8" ?>
- <!-- 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://service.hjg.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.hjg.com/" name="MyServiceImpService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://service.hjg.com/" schemaLocation="http://localhost:8888/ns?xsd=1" />
</xsd:schema>
</types>
- <message name="minus">
<part name="parameters" element="tns:minus" />
</message>
- <message name="minusResponse">
<part name="parameters" element="tns:minusResponse" />
</message>
- <message name="add">
<part name="parameters" element="tns:add" />
</message>
- <message name="addResponse">
<part name="parameters" element="tns:addResponse" />
</message>
- <portType name="IMyService">
- <operation name="minus">
<input wsam:Action="http://service.hjg.com/IMyService/minusRequest" message="tns:minus" />
<output wsam:Action="http://service.hjg.com/IMyService/minusResponse" message="tns:minusResponse" />
</operation>
- <operation name="add">
<input wsam:Action="http://service.hjg.com/IMyService/addRequest" message="tns:add" />
<output wsam:Action="http://service.hjg.com/IMyService/addResponse" message="tns:addResponse" />
</operation>
</portType>
- <binding name="MyServiceImpPortBinding" type="tns:IMyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="minus">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="add">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="MyServiceImpService">
- <port name="MyServiceImpPort" binding="tns:MyServiceImpPortBinding">
<soap:address location="http://localhost:8888/ns" />
</port>
</service>
</definitions>

web service1简单的例子用jdk自带的类的更多相关文章

  1. 使用JDK自带功能,实现一个简单的Web Service接口发布

    万事开头难,本篇文章的目的就是使用JDK自带的功能,实现一个最简单的Web Service接口的发布. 下图是项目的组成,主要有三个部分,一个接口(WS),一个接口的实现类(WSImp),还有一个接口 ...

  2. webservice和wcf和web.api简单介绍

    转自:无废话的wcf等等 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Ser ...

  3. Spring-Context之一:一个简单的例子

    很久之前就想系统的学习和掌握Spring框架,但是拖了很久都没有行动.现在趁着在外出差杂事不多,就花时间来由浅入深的研究下Spring框架.Spring框架这几年来已经发展成为一个巨无霸产品.从最初的 ...

  4. C#调用存储过程简单完整例子

    CREATE PROC P_TEST@Name VARCHAR(20),@Rowcount INT OUTPUTASBEGIN SELECT * FROM T_Customer WHERE NAME= ...

  5. Flask web开发 简单介绍

    Flask是一个基于python的轻量级web框架.当安装好后Flask后 (pip install flask),就可以开始使用了. 一.最简单的例子 1.新建目录,作为web应用的目录,如: mk ...

  6. Struts2的配置和一个简单的例子

    Struts2的配置和一个简单的例子 笔记仓库:https://github.com/nnngu/LearningNotes 简介 这篇文章主要讲如何在 IntelliJ IDEA 中使用 Strut ...

  7. javaweb简单登陆例子

    JSP+Servlet+JavaBean简单程序例子——用户名密码登陆,摘自<Tomcat&JavaWeb 技术手册>,亲测可用. IDE环境:MyEclipse10 1.建立We ...

  8. 跨站脚本功攻击,xss,一个简单的例子让你知道什么是xss攻击

    跨站脚本功攻击,xss,一个简单的例子让你知道什么是xss攻击 一.总结 一句话总结:比如用户留言功能,用户留言中写的是网页可执行代码,例如js代码,然后这段代码在可看到这段留言的不同一户的显示上就会 ...

  9. Jsp2.0自定义标签(第一天)——一个简单的例子

    今天是学习自定义标签的第一天 Jsp2.0以来,自定义标签的实现比传统标签的实现容易了很多,一般只要extends类SimpleSupport重写doTag()方法即可. 先看最简单的例子,输出一个H ...

随机推荐

  1. ASP.NET-FineUI开发实践-11

    我用实例项目写了个子父页面传值,算是比较灵活的写法,可以把js提取出来写成包,然后调用,我先一步一步写,为有困难的朋友打个样. 先画个页面: 上面是个查询用的表单,底下是表格,内存分页,用到了VBox ...

  2. python面对对象编程-------5:获取属性的四种办法:@property, __setattr__(__getattr__) ,descriptor

    一:最基本的属性操作 class Generic: pass g= Generic() >>> g.attribute= "value" #创建属性并赋值 > ...

  3. Python的基本配置

    Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结 ...

  4. Hibernate 报错org.hibernate.PropertyAccessException: IllegalArgumentException(已解决)

    无聊想搭建一个项目,练手,做点小功能就一个卡在这个问题上 org.hibernate.PropertyAccessException: IllegalArgumentException occurre ...

  5. HTML5 Canvas Text文本居中实例

    1.代码: <canvas width="700" height="300" id="canvasOne" class="c ...

  6. Google2016开发者大会

    Android主讲: 一.吴晶:android笔记博主(博客:http://www.race604.com/) 主题:Android低功耗蓝牙(BLE)实践 低功耗蓝牙在可穿戴和智能家居里边用的比较多 ...

  7. RAC检查各资源

  8. cas sso入门(转)

    转:http://blog.csdn.net/frinder/article/details/7969925 一.教程说明 前言 教程目的:从头到尾细细道来单点登录服务器及客户端应用的每个步骤 单点登 ...

  9. jquery mobile listview列表属性(搜索自动填充检索效果)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  10. [jstl] forEach标签使用

     在JSP的开发中,迭代是经常要使用到的操作.例如,逐行的显示查询的结果等.在早期的JSP中,通常使用Scriptlets来实现Iterator或者Enumeration对象的迭代输出.现在,通过JS ...