Xfire implements WebService server and client

Source: Internet
Author: User
Tags wsdl

Create a Web Service

1. Create a WEB Project
2. Right-click the project and choose myeclipse> Add xfire web service.

3. Create a web service and set it in a pop-up window

4. the system automatically adds File Analysis:

Service. xml

 
<? XML version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://xfire.codehaus.org/config/1.0"> <service> <Name> helloworld </Name> <serviceclass> hellows. ihelloworld </serviceclass> <implementationclass> hellows. helloworldimpl </implementationclass> <style> wrapped </style> <use> literal </use> <scope> application </scope> </service> </beans>

Ihelloworld. Java

Package hellows; // generated by myeclipsepublic interface ihelloworld {Public String example (string message );}

Helloworldimpl. Java

 
Package hellows; // generated by myeclipsepublic class helloworldimpl implements ihelloworld {Public String example (string message) {system. out. println (this); Return "Hello, this is my first web service. The message you entered is:" + message ;}}

5. Publish the running project and display the WSDL

The Web Service Listening address is:
Http: // localhost: 8080/helloworldservice/services/helloworld.
An error message is displayed:
Invalid SOAP request.

That is, invalid SOAP request. However, according to the Web service specifications, all web services must provide the WSDL description, so the Web service here also supports, just add? The WSDL parameter is enough. Visit the following address:

Http: // localhost: 8080/helloworldservice/services/helloworld? WSDL,
The output is as follows (we can see that WSDL is not for people ):

Create a Java test Client

We need to create a class in the helloworldservice project. The first step is to add the class library xfire HTTP client libraries to the Construction Path of the project. First, in the package Development E view, right-click the project root node, select the menu build path> Add library, and then select myeclipse libraries in the displayed add library dialog box, click Next to go to the next page, and select xfire 1.2 HTTP client libraries, 15.15
. Click Finish to end the process of adding a class library.

Then we can create a client class for testing and create a class client. hellowsclient,Source codeThe list is as follows:

 package wsclient; import java.net. malformedurlexception; import hellows. ihelloworld; import Org. codehaus. xfire. xfirefactory; import Org. codehaus. xfire. client. xfireproxyfactory; import Org. codehaus. xfire. service. *; import Org. codehaus. xfire. service. binding. objectservicefactory; public class hellowsclient {public static void main (string [] ARGs) {service srvcmodel = new objectservicefactory (). create (ihelloworld. class); xfireproxyfactory factory = new xfireproxyfactory (xfirefactory. newinstance (). getxfire (); string helloworldurl = "http: // 127.0.0.1: 8080/helloworldxfire/services/helloworld"; try {ihelloworld srvc = (ihelloworld) factory. create (srvcmodel, helloworldurl); string result = srvc. example ("Hello World Java client test"); system. out. print (result);} catch (malformedurlexception e) {e. printstacktrace () ;}}

OK. Run this class now to get the expected results:
hello, this is my first web service. The message you entered is: hello World Java client test

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.