发布WebService 1.1
2014-06-23 21:16
232 查看
webservice1.1是基于jdk发布的
测试:
一、用户访问http://192.168.151.42:5678/hello?wsdl 然后
cmd下输入 wsimport -s . http://192.168.151.42:5678/hello?wsdl
然后把代码下下来 去掉其中的*.class
复制代码到项目测试
在http://192.168.151.42:5678/hello?wsdl中采用从底向上的模式看
这样 就能实现 在客户端访问 服务端的WebService
还有一种客户端写法实现访问服务端, 这种方法其实和第一种本质是一样的,第一种方法采用继承接口的形式,客户端拷贝多个文件。
第二种方法客户端单单拷贝接口,因为继承这个接口的构造方法是protected,所以可以用第二种方法,代理对象
二 利用生成的接口 和jdk提供的 Service 等类 实现访问 这种方法比较折中,拷贝一个文件又能用
服务器端添加方法
然后 wsimport -s -p cn.itcast.hello http://192.168.151.42:5678/hello?wsdl
然后单单拷贝生成的接口 HelloService
然后以下代码
就可以访问了 服务端了
package cn.itcast.service01; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class HelloService { public String sayHello(String name) { System.out.println("say hello called"); return "hello " +name; } //main方法不能发布的, 发布的方法不能是静态 的 public static void main(String[] args) { //启动一个新线程 地址 内容 Endpoint.publish("http://192.168.151.42:5678/hello", new HelloService()); System.out.println("herer "); } }
测试:
一、用户访问http://192.168.151.42:5678/hello?wsdl 然后
cmd下输入 wsimport -s . http://192.168.151.42:5678/hello?wsdl
然后把代码下下来 去掉其中的*.class
复制代码到项目测试
在http://192.168.151.42:5678/hello?wsdl中采用从底向上的模式看
package cn.itcast.testService; import cn.itcast.service01.HelloService; import cn.itcast.service01.HelloServiceService; public class AppTest { public static void main(String[] args) { /** * wsdl 地址 service name="HelloServiceService" */ HelloServiceService service=new HelloServiceService(); HelloService soap=service.getHelloServicePort(); String str=soap.sayHello("this is sss "); System.out.println(str); } }
这样 就能实现 在客户端访问 服务端的WebService
还有一种客户端写法实现访问服务端, 这种方法其实和第一种本质是一样的,第一种方法采用继承接口的形式,客户端拷贝多个文件。
第二种方法客户端单单拷贝接口,因为继承这个接口的构造方法是protected,所以可以用第二种方法,代理对象
二 利用生成的接口 和jdk提供的 Service 等类 实现访问 这种方法比较折中,拷贝一个文件又能用
服务器端添加方法
public String sayHello2(String name,int n) { System.out.println("say hello called --------------------"+n); return "hello " +name; }
然后 wsimport -s -p cn.itcast.hello http://192.168.151.42:5678/hello?wsdl
然后单单拷贝生成的接口 HelloService
然后以下代码
package cn.itcast.testService; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import cn.itcast.hello.HelloService; public class AppTest2 { public static void main(String[] args) throws MalformedURLException { //命名空间 service Service s = Service.create(new URL("http://192.168.151.42:5678/hello?wsdl"), new QName("http://service01.itcast.cn/", "HelloServiceService")); //命名空间 服务绑定的port HelloService hs = s.getPort(new QName("http://service01.itcast.cn/","HelloServicePort"), HelloService.class); String str = hs.sayHello2("lisi",10); System.out.println(str); System.out.println(hs.getClass().getSimpleName()); } }
就可以访问了 服务端了
相关文章推荐
- 1.1 发布webservice 服务
- tomcat发布基于jersey的WebService(一)
- Axis2 发布webservice
- 真正的轻量级WebService框架——使用JAX-WS(JWS)发布WebService
- 用JAX-WS在Tomcat中发布WebService
- VS2013创建、发布一个webservice
- SAP用Function发布供外部调用的webservice
- 带你走进EJB--将EJB发布为Webservice(3)
- ASP.NET(v 1.1) 程序发布时如何带上IE WebControls
- 解决“Webservice发布本机上可以用,但是别的电脑搜不到Webservice”的问题
- Flex 调用Webservice服务发布的数据
- SpringBoot整合cxf发布WebService服务和客户端调用WebService服务
- 服务端使用Axis2-1.6.3发布webservice服务、客户端使用Axis1.4实现调用
- spring集成axis2以接口方式发布webservice
- rails 1.1 发布相关
- WebSphere 下发布webservice
- cxf发布webservice 服务
- 【JQUBAR1.1】jQuery 插件发布
- webservice接口发布概述