您的位置:首页 > 编程语言 > Java开发

纯Java发布javax.jws.WebService(不用CXF axis等框架)

2015-04-25 23:30 423 查看
1.创建interface 带WebService注解。

package service;

import javax.jws.WebService;

@WebService
public interface CallService {

public void callSomeOne(String name);

}


2.完成实现类,带WebService注解。
package service.impl;

import javax.jws.WebService;

import service.CallService;

@WebService(endpointInterface="service.CallService")
public class CallServiceImplA implements CallService {

@Override
public void callSomeOne(String name) {
// TODO Auto-generated method stub

System.out.println("Hi, "+name+", I'm calling you");

}

}


3.启动服务
package service;

import javax.xml.ws.Endpoint;

import service.impl.CallServiceImplA;

public class CallServer {

public static void main(String[] args) {
System.out.println("server starting...");
String address = "http://localhost:8889/service/call";
Endpoint.publish(address, new CallServiceImplA());
System.out.println("server started.");
}

}


4.客户端访问服务

package service;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class CallClient {
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://localhost:8889/service/call");
QName qName = new QName("http://impl.service/", "CallServiceImplAService");

Service service = Service.create(url, qName);
CallService cs = service.getPort(CallService.class);
cs.callSomeOne("wumz");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: