CXF Dynamic Client Invoke WebService instance

Source: Internet
Author: User
Tags wsdl

Use CXF to implement WebService, and implement dynamic invocation on the client to write server considerations

Note: Do not specify
@SOAPBinding (STYLE=STYLE.RPC, use=use.literal) because CXF does not support: RPC, encoded, calling procedures in dynamic clients.

CXF WebService Development data, a search on the internet is mostly similar to the official example.
Are simple examples of static calls. There are very few data and errors for dynamic invocations. I was tossing the case without the
In a buddy's blog see that dynamic calls do not support RPC.
Server side:
Package com.rodjson.cxf;

Import Javax.jws.WebMethod;
Import Javax.jws.WebParam;
Import Javax.jws.WebService;

/* @SOAPBinding (STYLE=STYLE.RPC, use=use.literal) Note: If you want to dynamically invoke must comment out this code.
Public interface HelloWorld {
String Sayhi (@WebParam (name= "text") string text);
Package com.rodjson.cxf;
Import Javax.jws.WebService;

@WebService (endpointinterface= "Com.rodjson.cxf.HelloWorld",

Servicename= "HelloWorld")
public class Helloworldimpl implements HelloWorld {

public string Sayhi (string text) {
System.out.println ("Sayhi called");
Return "Hello" + text;


Package com.rodjson.cxf;


public class Webserviceapp {
public static void Main (string[] args) {
SYSTEM.OUT.PRINTLN ("Web service Start");
HelloWorld implementor = new Helloworldimpl ();
String address = "Http://localhost:8080/helloWorld";
Endpoint.publish (address, implementor);
SYSTEM.OUT.PRINTLN ("Web Service End");

As for the deployment of methods on the Web a lot, I do not mention, the focus is on dynamic client invocation and error recognition

Package com.rodjson.cxf;

Import org.apache.cxf.endpoint.Client;
Import Org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class Clientobj {
public static void Main (string[] args) {
Jaxwsdynamicclientfactory factory =jaxwsdynamicclientfactory.newinstance ();
Client Client =factory.createclient ("http://localhost:8080/cxf/services/HelloWorld?wsdl");
try {
object[] obj =client.invoke ("Sayhi", "Xiao");
System.out.println ("RESP:" +obj[0]);
catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();

The error is as follows:
2012-5-23 20:53:34 org.apache.cxf.common.jaxb.JAXBUtils Loggeneratedclassnames

Info: Created classes:

Javactask: no source files

Usage: javactask <options> <source files>

-help is used to list possible options

2012-5-23 20:53:34 org.apache.cxf.endpoint.dynamic.DynamicClientFactory createclient

Serious: Could not compile Java files for

If you think this article is helpful to you, please don't skimp on your mouse, help the blogger,
Into the Bo Master opened the programmer Tea Shop: to gather personal gas. Thank you very much.

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: 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.