服务器端建立
创建接口
package com.test.webservice; import javax.jws.WebService; @WebService public interface TestInterface { public int add(int a,int b); public int minus(int a,int b); }
创建实现类
package com.test.webservice; import javax.jws.WebService; @WebService(endpointInterface="com.test.webservice.TestInterface") public class TestImp implements TestInterface { public int add(int a, int b) { System.out.println("加法"); return a+b; } public int minus(int a, int b) { System.out.println("减法"); return a-b; } }
发布服务
package com.test.webservice; import javax.xml.ws.Endpoint; public class MyService { public static void main(String[] args){ String address = "http://192.168.1.105:8989/ns"; Endpoint.publish(address, new TestImp()); } }
客户端建立
使用wsimport命令生成客户端代码
E:\>wsimport -d e:/webservice/01/ -keep -verbose http://192.168.1.105:8989/ns?ws
dl
调用客户端代码
package com.test.webservice; public class Client { /** * @param args */ public static void main(String[] args) { TestImpService testImpService = new TestImpService(); TestInterface testInterface = testImpService.getTestImpPort(); int result = testInterface.add(1, 2); System.out.println(result); } }
基于jax-ws的webservice 简单实例
原创xiaomin_java 博主文章分类:webservice ©著作权
©著作权归作者所有:来自51CTO博客作者xiaomin_java的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
JAX-WS实做webservice验证
在JAX WS标准中,做websevice变得容易,都是用注解等就可以实现了,其中用来做webservice的权限也是很容易的,比如要根据用户
webservice List ide java -
基于jdk6的WebService~JAX-WS 方法
工具:Eclipse说明:我知道的WebService的一点点的作用,例如:天气预报,这样的一个项目,应该很庞大,并不是所有的公司
jdk webservice java 客户端 服务器端 -
在tomcat中部署JAX-WS webservice
在tomcat中部署WEB SERVICE 呵呵,花了一个下午总算搞定了,现在整理一下思路。 这是一个简单
tomcat部署webservice webservice Web java 字符串 -
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
前两篇关于使用Axis2开发WebService,都是使用了services.xml文件,而且还要拷贝axis2.war下面的文件到项目中,
web service axis2 jax-ws xml apache