Cxf calls WebService

Source: Internet
Author: User
Tags webp

The service address published on the server is http: // localhost: 8080/webp/WebService/helloworld.

1) Visit the client first to see if it can be accessed. Add URL + to the address published on the server? WSDL; for example: http: // localhost: 8080/webp/WebService/helloworld? WSDL
Access.

If you see the XML document information, it means it is normal.

2) in DOS input cmd run, find the decompressed apache-cxf-2.6.1 bin directory, run

Wsdl2java-P ws http: // localhost: 8080/webp/WebService/helloworld? WSDL generates the WS folder in the bin directory of the apache-cxf-2.6.1

-P is the package corresponding to the package in Java.

-D: Enter the directory to generate the. Java file. The package directory of-P is generated under this directory.

-The client generates the code for the client to test the web service. -The server generates the server code to start the web service. -impl is used to generate the Web service implementation code. -Ant generate build. XML file. -All: generate all files corresponding to-client-server-impl-ant above.


3) Place the java files in the generated ws folder in your project. These java files are the classes required to call WebService.


4) run the test class

Import java. util. arraylist;
Import java. util. List;

Import org. Apache. cxf. jaxws. jaxwsproxyfactorybean;

Import ws. helloworld;
Import ws. user;
 
Public class helloworldclient {
 
 Public static void main (string [] ARGs ){
  Jaxwsproxyfactorybean SVR = new jaxwsproxyfactorybean ();
  SVR. setserviceclass (helloworld. Class );
  SVR. setaddress ("http: // localhost: 8080/webp/WebService/helloworld ");
  Helloworld hW = (helloworld) SVR. Create ();
  User user = new user ();
  User. setname ("tony1 ");
  System. Out. println (HW. sayhitouser (User ));
  System. Out. println (HW. sayhi ("Wang "));
  
  List <user> List = new arraylist <user> ();
  List. Add (User );
  System. Out. println (HW. sayhitouserlist (list ));
 }
}

Output result, over!


Reprinted: http://blog.sina.com.cn/s/blog_8ee5914d01016ctl.html



Method 1: Call through clientproxyfactorybean

Public static <t> T getservice (string URL, class <t> CLs ){
Clientproxyfactorybean factory = new clientproxyfactorybean ();
Factory. setserviceclass (CLS );
Factory. setaddress (URL );
T service = (t) Factory. Create ();
Return service;
}

 

Method 2: Call through jaxwsdynamicclientfactory

Jaxwsdynamicclientfactory DCF = jaxwsdynamicclientfactory. newinstance ();
Client client = DCF. createclient ("http: // 192.168.1.102: 12000/testservice? WSDL ");

Object [] objects = client. Invoke ("test", "test ARGs ");

 

Note: When cxf-dosgi releases WebService, you only need to add the following Configuration:

Dictionary <string, string> props = new hashtable <string, string> ();
Props. Put ("service. exported. interfaces ","*");
Props. Put ("service. exported. intents", "Soap ");
Props. Put ("service. exported. configs", "org. Apache. cxf. ws ");
Props. Put ("org. Apache. cxf. ws. Address", "http: // 192.168.1.102: 12000/testservice? WSDL ");

Reprinted: http://blog.csdn.net/einarzhang/article/details/6225921



Http://kyfxbl.iteye.com/blog/1432952

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.