备忘,简单的发布WebService ,可能会报错,请把jdk升级到1.6u45以上

简单的发布webservice备忘。
interface
package com;


import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface IMyService {
	
	@WebResult(name="addResult")
	public int add(@WebParam(name="a")int a,@WebParam(name="b")int b);
	
	@WebResult(name="minusResult")
	public int minus(@WebParam(name="a")int a,@WebParam(name="b")int b);
	
	@WebResult(name="user")
	public User getUser(@WebParam(name="id")int id);
	
}

implements
package com;

import javax.jws.WebService;

@WebService(endpointInterface="com.IMyService")
public class MyServiceImpl 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;
	}

	@Override
	public User getUser(int id) {
		User user = new User();
		user.setId(id);
		user.setName("夏");
		user.setPassword("123");
		return user;
	}
}

实体类
package com;

public class User {
	private int id;
	private String name;
	private String password;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
}

发布服务
package com;

import javax.xml.ws.Endpoint;

public class MyServer {

	public static void main(String[] args) {
		String address = "http://localhost:8080/test";
		Endpoint.publish(address, new MyServiceImpl());
	}
}


浏览器输入 http://localhost:8080/test?wsdl


你可能感兴趣的:(webservice)