Use xfire to develop a web service client

Source: Internet
Author: User

Although xfire has been replaced by cxf, many projects that have been developed still use xfire to implement web services. Some time ago, my article "xfire complete getting started tutorial" for developing Web service servers using xfire was well received and brought convenience and pleasure to everyone. Let's talk about xfire client development today.

This article will continue to use the server of the previous article as the server. Using xfire to develop Web service clients can be divided into the following two categories:
1. The service provider tells you that you can develop interfaces in the following three ways:
Yourservice is an interface that the service provider tells you (you can also define the same interface according to the definition of WSDL ).
1. The simple method is service servicemodel = new objectservicefactory (). Create (yourservice. Class );
Yourservice service = (yourservice)
New xfireproxyfactory (). Create (servicemodel, "http: // your/remote/url ");

2. JSR 181 annotation method: Service servicemodel = new annotationservicefactory (). Create (yourservice. Class );
Yourservice client = (yourservice)
New xfireproxyfactory (). Create (servicemodel, "http: // your/remote/url ");

3. Hybrid service servicemodel =
New annotationservicefactory (
New jsr181webannotations (),
Xfirefactory. newinstance (). getxfire (). gettransportmanager (),
New aegisbindingprovider (New jaxbtyperegistry (). Create (yourservice. Class );

2. Create a dynamic client using WSDL, as shown below: package test;

Import java.net. malformedurlexception;
Import java.net. url;

Import org. codehaus. xfire. Client. client;

Public class dynamicclienttest {
Public static void main (string [] ARGs) throws malformedurlexception,
Exception {
Client client = new client (new URL (
"Http: // localhost: 8080/xfiretest/services/testservice? WSDL "));
Object [] Results = client
. Invoke ("sayhello", new object [] {"firends "});
System. Out. println (results [0]);

}
}

3. Use ant tool or command line to generate a client through WSDL:
1. Use ant to generate the client. The ant script is as follows: <? XML version = "1.0"?>
<Project name = "wsgen" default = "wsgen" basedir = ".">
<Path id = "classpathid">
<Fileset dir = "./webroot/WEB-INF/lib">
<Include name = "*. Jar"/>
</Fileset>
</Path>
<Taskdef classpathref = "classpathid" name = "wsgen" classname = "org. codehaus. xfire. gen. wsgentask">
</Taskdef>
<Target name = "wsgen" Description = "generate client">
<Wsgen outputdirectory = "./src/" WSDL = "ABC. WSDL" binding = "xmlbeans" package = "com. ABC. P" Overwrite = "true"/>
</Target>
</Project>

Note that the script has a binding parameter, which can be specified in two different ways:
(1) jaxb (Java architecture for XML binding, https://jaxb.dev.java.net/): When this method is used, more request and resopnse classes are automatically generated.
(2) xmlbeans
The call method is as follows: abcserviceclient client = new abcserviceclient ();
String url = "http: // localhost: 8080/xfiretest/services/testservice ";
String result = client. getabcport (URL). sayhello ("Robin ");

2, use the command to generate the client command as follows: gpath = xfire-all-1.2-SNAPSHOT.jar: ant-1.6.5.jar: jaxb-api-2.0EA3.jar: stax-api-1.0.1.jar: jdom-1.0.jar: jaxb-impl-2.0EA3.jar \
: Jaxb-xjc-2.0-ea3.jar: wstx-asl-2.9.3.jar: commons-logging-1.0.4.jar: activation-1.1.jar: wsdl4j-1.5.2.jar: XmlSchema-1.0.3.jar: xfire-jsr181-api-1.0-M1.jar;

Java-CP $ gpath org. codehaus. xfire. gen. wsgen-WSDL http: /localhost: 8080/xfire/services/bookservice? WSDL-o.-P pl. tomeks. Client-overwrite true

The result is the same as that generated by ant.

Iv. Reference resources:
1, xfire 1.2.6 Manual (http://xfire.codehaus.org/User%27s+Guide)
Http://xfire.codehaus.org/Client+API 2
3, http://xfire.codehaus.org/Dynamic+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.