A server-side webservice has been successfully released in the previous section. In this section, the default Client is called webservice. Here we re-establish a new project CXF-Client, run the jar packages listed in the previous section. The Calling method adopts the RMI mechanism, that is, the interface provided by the client directly on the server.
A server-side webservice has been successfully released in the previous section. In this section, the default Client is called webservice. Here we re-establish a new project CXF-Client, run the jar packages listed in the previous section. The Calling method adopts the RMI mechanism, that is, the interface provided by the client directly on the server.
A server webservice has been successfully released in the previous section. This section uses the default client to call webservice.
Here we have re-established a new project CXF-Client, and we can get all the jar packages listed in the previous section. The Calling method adopts a mechanism similar to RMI, that is, the Service interface (interface) provided by the client directly on the server side. CXF generates a remote service proxy object through runtime, and completes access to webservice on the client.
Required fields: setAddress-this is the address when we release webservice.
HelloWorldService: the server must provide a separate Jar file.
package com.crazycoder2010.webservice.cxf.client;import org.apache.cxf.interceptor.LoggingInInterceptor;import org.apache.cxf.interceptor.LoggingOutInterceptor;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;import com.crazycoder2010.webservice.cxf.server.HelloWorldService;public class Client {public static void main(String[] args) {JaxWsProxyFactoryBean bean = new JaxWsProxyFactoryBean();bean.getInInterceptors().add(new LoggingInInterceptor());bean.getInFaultInterceptors().add(new LoggingOutInterceptor());bean.setServiceClass(HelloWorldService.class);bean.setAddress("http://localhost:9090/helloWorldService");HelloWorldService helloWorldService = (HelloWorldService)bean.create();String result = helloWorldService.sayHello("Kevin");System.out.println(result);}}
Running output:
2011-8-9 21:32:20 org. apache. cxf. service. factory. reflectionServiceFactoryBean buildServiceFromClass information: Creating Service {http://server.cxf.webservice.crazycoder2010.com/#helloworldserviceservice from class com. crazycoder2010.webservice. cxf. server. helloWorldService2011-8-9 21:32:41 org. apache. cxf. interceptor. abstractLoggingInterceptor log information: Inbound Message ---------------------------- ID: 1Response-Code: 200 Encoding: UTF-8Content-Type: text/xml; charset = "UTF-8" Headers: {Content-type = [text/xml; charset = "UTF-8"], Transfer-encoding = [chunked]} Payload:
Hello Kevin
-------------------------------------- Hello KevinSummary: The advantage of this service call is that the call process is very simple. A webservice call can be completed with just a few lines of code, but the client must also rely on the server interface, this method of calling is very limited, and the webservice on the server must be implemented in java -- this will lose the meaning of using webservice.