标签:style blog http color io os 使用 java ar
. 创建一个 webService 工程。
package com.hmw.jaxws;
/**
* 提供 WebService 服务的测试类<br>
* <b>注意:</b>该类必须有一个无参构造方法,否则无法使用 MyEclipse 的向导为此类创建 jax-ws 的 webService 服务端类<br>
* <b>创建日期</b>:2011-1-17
* @author <a href="mailto:hemingwang0902@126.com" mce_href="mailto:hemingwang0902@126.com">何明旺</a>
*/
public class HelloJaxws {
public String sayHello(String userName) {
return userName + ",您好,这是我的第一个 jax-ws 程序。";
}
public int add(int i, int j) {
return i + j;
}
}
[java] view plaincopy
package com.hmw.jaxws;
/**
* 提供 WebService 服务的测试类<br>
* <b>注意:</b>该类必须有一个无参构造方法,否则无法使用 MyEclipse 的向导为此类创建 jax-ws 的 webService 服务端类<br>
* <b>创建日期</b>:2011-1-17
* @author <a href="mailto:hemingwang0902@126.com" mce_href="mailto:hemingwang0902@126.com">何明旺</a>
*/
public class HelloJaxws {
public String sayHello(String userName) {
return userName + ",您好,这是我的第一个 jax-ws 程序。";
}
public int add(int i, int j) {
return i + j;
}
}
HelloJaxwsDelegate.java 的源代码如下:
package com.hmw.jaxws;
@javax.jws.WebService(targetNamespace = "http://jaxws.hmw.com/", serviceName ="HelloJaxwsService", portName = "HelloJaxwsPort", wsdlLocation = "WEB-INF/wsdl/HelloJaxwsService.wsdl")
public class HelloJaxwsDelegate {
com.hmw.jaxws.HelloJaxws helloJaxws = new com.hmw.jaxws.HelloJaxws();
public String sayHello(String userName) {
return helloJaxws.sayHello(userName);
}
public int add(int i, int j) {
return helloJaxws.add(i, j);
}
}
[java] view plaincopy
package com.hmw.jaxws;
@javax.jws.WebService(targetNamespace = "http://jaxws.hmw.com/", serviceName = "HelloJaxwsService", portName = "HelloJaxwsPort", wsdlLocation = "WEB-INF/wsdl/HelloJaxwsService.wsdl")
public class HelloJaxwsDelegate {
com.hmw.jaxws.HelloJaxws helloJaxws = new com.hmw.jaxws.HelloJaxws();
public String sayHello(String userName) {
return helloJaxws.sayHello(userName);
}
public int add(int i, int j) {
return helloJaxws.add(i, j);
}
}
整个项目的目录结构如下图所示:
测试类 ClientTest.java 的代码如下:
package com.hmw.client.jaxws;
public class ClientTest {
public static void main(String[] args) {
HelloJaxwsDelegate service = new HelloJaxwsService().getHelloJaxwsPort();
System.out.println(service.sayHello("hemingwang"));
System.out.println("result is: " + service.add(1, 2));
}
}
[java] view plaincopy
package com.hmw.client.jaxws;
public class ClientTest {
public static void main(String[] args) {
HelloJaxwsDelegate service = new HelloJaxwsService().getHelloJaxwsPort();
System.out.println(service.sayHello("hemingwang"));
System.out.println("result is: " + service.add(1, 2));
}
}
整个项目的目录结构如下图所示:
运行结果如下图所示:
标签:style blog http color io os 使用 java ar
原文地址:http://my.oschina.net/u/1866821/blog/312909