Xfire Demo Instance

Source: Internet
Author: User

(i) Release of WebService services through Xfire 1. Add Xfire related jar packages (Maven for example): <dependency> <groupid>org.codehaus.xfire</grou Pid> <artifactId>xfire-all</artifactId> <version>1.2.6</version> </dependency>2. Configuration web.xml     <servlet>        < servlet-name>xfireservlet</servlet-name>        <servlet-class >org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>         <load-on-startup>0</load-on-startup>    </servlet>          <servlet-mapping>        < servlet-name>xfireservlet</servlet-name>        <url-pattern> /services/*</url-pattern>//Service Release match address     </servlet-mapping>3. Create a service interface &NBSP;&NBSP;&NBSp; package Demo;    public Interface Servertest {                    void Say (String str);     } 4. Creating an implementation class implementationServertestpackage Demo;public class Servertestimpl implements Servertest {public void Say (String str) {System.    Out.println (str); }}5. Definition Services.xml--[Web-inf\classes\meta-inf\xfire ] Publish WebService Configuration     No this file need to create <?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "/http xfire.codehaus.org/config/1.0 ">                 <service>           <name>Test</name>  //define the publication name of the WebService         <namespace>haople</namespace>    //defines the WebService namespace         <serviceclass>demo. servertest</serviceclass>   //Interface Classes         < Implementationclass>demo. servertestimpl</implementationclass> //Implementation Classes     </service>               </beans> After starting service: Access http://127.0.0.1:8080/demo/ SERVICES/TEST?WSDL   (ii) Xfire Client Call WebService service method one:     package demo;import org. Codehaus.xfire.client.xfireproxyfactory;import Org.codehaus.xfire.service.service;import Org.codehaus.xfire.service.binding.objectservicefactory;public class Clienttest {    public static void Main (string[] args) {        try {        service Service=new objectservicefactory (). Create (Servertest.class); Create service         servertest test= (servertest) New Xfireproxyfactory (). Create (Service, " Http://127.0.0.1:8080/demo/services/Test "); Proxy Service (not WSDL address here)          Test.say ("Hello word!"); Execution methods         } catch (Exception e) {           & Nbsp;e.printstacktrace ();        }    }    } Method Two: Package Demo;import Java.net.url;import Org.codehaus.xfire.client.client;public class Clienttest {    public static void Main (string[] ARGS) {        try {                     client client=new Client (New URL ("http://127.0.0.1:8080/demo/services/Test?wsdl")); The WSDL address is accessed here             client.invoke ("Say", New object[]{"Hello World! "}); The first parameter is the execution method name, the second parameter is the executed argument, the return is object[]         } catch (Exception e) {            e.printstacktrace ();        }     }}



Xfire Demo Instance

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.