CXF SOAP-style +spirng4+maven client

Source: Internet
Author: User
Tags soap client

The previous blog describes the CXF soap-style server, and now we write the client to invoke

1, Pom.xml

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.jacky</groupId>  <Artifactid>Cxf_client</Artifactid>  <version>0.0.1-snapshot</version>  <Packaging>Jar</Packaging>  <name>Cxf_client</name>  <URL>http://maven.apache.org</URL>  <Properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  </Properties>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>    <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-frontend-jaxws</Artifactid>            <version>2.6.1</version>        </Dependency>        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-context</Artifactid>            <version>3.1.2.RELEASE</version>        </Dependency>        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-web</Artifactid>            <version>3.1.2.RELEASE</version>        </Dependency>        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-transports-common</Artifactid>            <version>2.5.4</version>            <type>Jar</type>            <Scope>Compile</Scope>        </Dependency>        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-core</Artifactid>            <version>2.6.1</version>            <type>Jar</type>            <Scope>Compile</Scope>        </Dependency>        <Dependency>            <groupId>Org.apache.cxf</groupId>            <Artifactid>Cxf-rt-transports-http-jetty</Artifactid>            <version>2.6.1</version>            <type>Jar</type>            <Scope>Compile</Scope>        </Dependency>  </Dependencies></Project>

2.info.xml

 PackageCom.jacky; Public classInfo {PrivateString name; Private intAge ;  PublicString GetName () {returnname; }       Public voidsetName (String name) { This. Name =name; }       Public intGetage () {returnAge ; }       Public voidSetage (intAge ) {           This. Age =Age ; } @Override PublicString toString () {return"Info [name=" + name + ", age=" + Age + "]"; }      }

3, App.java

 PackageCom.jacky;Importorg.apache.cxf.endpoint.Client;ImportOrg.apache.cxf.jaxws.JaxWsProxyFactoryBean;Importorg.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;Importorg.junit.Test;ImportCom.jacky.service.GetInfoService;/*** Hello world! **/ Public classApp {/*** Introduction: The invocation of a similar mechanism with RMI, that is, the client directly server-side service Interface (interface), * CXF through the runtime proxy to generate the remote service proxy object, * on the client to complete the access to WebService;      Required Fields: * setaddress-This is the address we posted when we webservice, keep it consistent. Cons: The benefit of invoking a service is that the invocation process is very simple, with a few lines of code completing a webservice call, * But the client must also rely on the server-side interface, which is very restrictive, and requires the server-side webservice to be a J  Ava implementation-This also loses the meaning of using WebService. */@Test Public voidtest1 () {Jaxwsproxyfactorybean bean=NewJaxwsproxyfactorybean (); Bean.setserviceclass (Getinfoservice.class); Bean.setaddress ("Http://localhost:8080/cxf_demo/cxf/getInfoService"); Getinfoservice Service=(Getinfoservice) bean.create (); intresult = Service.add (1, 1); System.out.println ("result=====" +result); Info Info= Service.getinfo ("Lo Zhimao", 21); System.out.println ("info===" +info); }   /*** Introduction: Simply specify the location of the server-side WSDL file, then specify the parameters of the method and method to invoke, and do not care about how the service side is implemented. * WSDL [Web Services Description Language] Network Service Description Language is the description language of a Web service that contains a series of definitions that describe a Web service *@throwsException*/@Test Public voidTest2 ()throwsException {jaxwsdynamicclientfactory clientfactory=jaxwsdynamicclientfactory.newinstance (); Client Client= Clientfactory.createclient ("http://localhost:8080/cxf_demo/cxf/getInfoService?wsdl"); Object[] Objs={1,2}; Object[] Result= Client.invoke ("Add", OBJS); System.out.println (result[0]); }}

In this case, the two invocation methods of the CXF SOAP client are all written.

Link: http://pan.baidu.com/s/1mi376Es Password: ljy6

CXF SOAP-style +spirng4+maven client

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.