1 package cn.itcast.service;
2
3 import javax.jws.WebMethod;
4 import javax.jws.WebParam;
5 import javax.jws.WebResult;
6 import javax.jws.WebService;
7 import javax.xml.ws.Endpoint;
8 /**
9 * 将 Java 类标记为实现 Web Service,或者将 Java 接口标记为定义 Web Service 接口
10 * @author
11 *
12 */
13 //修改目标空间 ,修改服务名 在wsdl那里的xml文件显示对应的修改信息
14 @WebService(targetNamespace="http://www.itcast.cn",serviceName="MyService")
15 public class HelloService {
16 //修改方法名 返回值的名字
17 @WebMethod(operationName="hello")
18 @WebResult(name="ret")
19 public String sayHello(
20 //修改参数名字
21 @WebParam(name="name")
22 String name,
23 @WebParam(name="age")
24 int age){
25 System.out.println("sayHello called...");
26 return "hello " + name;
27 }
28 //此方法 本系统测试 不对外发布
29 @WebMethod(exclude=true)
30 public String sayHello2(String name){
31 System.out.println("sayHello called...");
32 return "hello " + name;
33 }
34
35 public static void main(String[] args) {
36 //参数1:绑定服务的地址 参数2:提供服务的实例
37 Endpoint.publish("http://192.168.1.101:5678/hello", new HelloService());
38 System.out.println("server ready...");
39 }
40 }