webservice的客户端实现有如下四种方式:
一、WSDL2Java generated Client
HelloService service = new HelloService();
Hello client = service.getHelloHttpPort();
String result = client.sayHi("Joe");
二、JAX-WS Proxy
Instead of using a wsdl2java-generated stub client directly, you can use Service.create to create Service instances, the following code illustrates this process:
import java.net.URL;
import javax.xml.ws.Service;
...
URL wsdlURL = new URL("http://localhost/hello?wsdl");
QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
Service service = Service.create(wsdlURL, SERVICE_NAME);
Greeter client = service.getPort(Greeter.class);
String result = client.greetMe("test");
3、ClientProxyFactoryBean – Making a Client Proxy
import demo.hw.server.HelloWorld;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
...
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/Hello");
HelloWorld client = (HelloWorld) factory.create();
4、Dynamic Client
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("echo.wsdl");
Object[] res = client.invoke("echo", "test echo");
System.out.println("Echo response: " + res[0]);
Many WSDLs will have more complex types though. In this case the JaxWsDynamicClientFactory takes care of generating Java classes for these types. For example, we may have a People service which keeps track of people in an organization. In the sample below we create a Person object that was generated for us dynamically and send it to the server using the addPerson operation:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("people.wsdl", classLoader);
Object person = Thread.currentThread().getContextClassLoader().loadClass("com.acme.Person").newInstance();
Method m = person.getClass().getMethod("setName", String.class);
m.invoke(person, "Joe Schmoe");
client.invoke("addPerson", person);
分享到:
相关推荐
WebService开发客户端 cxf方式
Java 调用webservice cxf客户端调用demo和服务端,包含jar包,服务端发布后直接用客户端调用
springboot整合CXF发布webservice和客户端调用 项目中每个类都有详细的注释,保证都能看懂,不失为一个学习springboot整合cxf来学习webservice发布调用的好例子
1.使用Java 2.用cxf开发webservice ...客户端也需要接口类文件和pojo,和cxf客户端xml 但是没有接口的实现类,就是为了去服务端来调用的。 具体有不懂可以问我 给我发消息, 劳烦评价 ,请大家支持原创 禁止转载
cxf 开发webservice客户端 代码经过测试
webservice cxf 客户端创建实例
springmvc+mybatis+cxf+客户端+服务器端+soap+rest方式+内部有数据库
webservice的cxf框架客户端调用所需jar包,不要删除里面的jar包,直接放在lib下。亲测可用。
CXF 一个完整的webService(整合客户端和服务端),自己开发,自己测试,完全有效,整合集成了客户端和服务端双向的工能。
cxf框架的webservice,可以完美运行,生成了xml字符串并进行传递以及生成了json对象,客户端进行请求并解析数据
使用cxf wsdl2java生成webservice客户端命令
使用cxf和spring开发基于https的webservice服务端以及客户端样例
apache-cxf-2.7.7以及cxf客户端所需要的jar包,命令生成webservice客户端
cxf生成webservice客户端
cxf webService
CXF webservice 动态地址客户端相关代码和jar包 CXF webservice 动态地址客户端相关代码和jar包
webservice客户端,框架为CXF,生成客户端的方式为自动(myeclipse生成)
使用CXF生成动态调用webservice接口的客户端,也比较简单。
cxf客户端调用webservice所需jar包