WebService(1)——使用JDK开发WebService
发布时间:2020-12-16 22:51:17 所属栏目:安全 来源:网络整理
导读:服务器端开发 新建一个java工程,写一个接口,加上注解,@WebService和@WebMethod package com.ws.service; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface HelloWS { @WebMethod String sayHello(String name);}
服务器端开发
package com.ws.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface HelloWS {
@WebMethod
String sayHello(String name);
}
package com.ws.service;
import javax.jws.WebService;
@WebService
public class HelloWSImpl implements HelloWS {
@Override
public String sayHello(String name) {
return "hello "+name;
}
}
package com.ws.main;
import javax.xml.ws.Endpoint;
import com.ws.service.HelloWSImpl;
public class Main {
public static void main(String[] args) {
//必须写本地IP
String address = "http://172.17.202.155:9999/ws01/hellows";
Endpoint.publish(address,new HelloWSImpl());
System.out.println("发布成功");
}
}
客户端开发
package com.ws.service.client.test;
import com.ws.service.HelloWSImpl;
import com.ws.service.HelloWSImplService;
public class Main {
public static void main(String[] args) {
// 调用webservice
HelloWSImplService factory = new HelloWSImplService();
HelloWSImpl helloWS = factory.getHelloWSImplPort();
System.out.println(helloWS.sayHello("tom"));
}
}
客户端开发完毕 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容