http://www.w3school.com.cn/ws.asp
?
class="java" name="code">package com.scb.simon.service; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class ServiceHello { public String sayhello(String name){ return "Hello, " + name; } public static void main(String[] args) { // TODO Auto-generated method stub Endpoint.publish("http://localhost:8081/service/serviceHello", new ServiceHello()); System.out.println("service bind successfully."); } }
?
?
运行,打印"monospace; line-height: 1.5; background-color: #fafafa;">service bind successfully."说明绑定服务成功。
通过http://localhost:8081/service/serviceHello?wsdl测试是否能够正确拿到wsdl。
wsimport -s?D:/workplace/graduationDesign/TheClient/src?-p com.scb.simon.client -keep?http://localhost:8081/service/serviceHello?wsdl
?
然后刷新项目,就可以看到生成的代码了。
?
?
?
package com.scb.simon.test;
import com.scb.simon.client.ServiceHello;
import com.scb.simon.client.ServiceHelloService;
public class TestService {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ServiceHello hello = new ServiceHelloService().getServiceHelloPort();
System.out.println(hello.sayhello("Simon"));
}
}
?
?
?console打印:Hello, Simon,说明测试成功。
?