CXF Study Notes (2)

Source: Internet
Author: User
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 Kevin
Summary: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.