Images and texts -- use xfire to compile WebService

Source: Internet
Author: User

Images and texts -- use xfire to compile WebService

I have never studied the axis series. I first learned xfire. myeclipse5.1 supports xfire very well. Here is a simple example,
1. First create a Web Service Project:



After you click Finish, myeclipse will automatically generate services for you. XML and Web application directory structure, where services. XML is the configuration file you export the service, note in WEB-INF/web. xfire servlet is configured in the XML file. <Servlet>
<Servlet-Name> xfireservlet </servlet-Name>
<Servlet-class> org. codehaus. xfire. Transport. http. xfirepolicableservlet </servlet-class>
<Load-on-startup> 0 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> xfireservlet </servlet-Name>
<URL-pattern>/services/* </url-pattern>
</Servlet-mapping>

2. Now, write the pojo class to be exported. The first is the interface: Package net. rubyeye. webservicedemo;

// Generated by myeclipse

Public interface ihelloworldservice {

Public String sayhello (string name );

}

This interface only provides one method: sayhello (). We do not use the jsr181 annotation declaration method or xml configuration file. Then there is the implementation class: Package net. rubyeye. webservicedemo;

// Generated by myeclipse

Public class helloworldserviceimpl implements ihelloworldservice {

Public String sayhello (string name ){
Return "hello," + name;
}


}

Finally, configure the services. xml file: <Service>
<Name> helloworldservice </Name>
<Serviceclass>
Net. rubyeye. webservicedemo. ihelloworldservice
</Serviceclass>
<Implementationclass>
Net. rubyeye. webservicedemo. helloworldserviceimpl
</Implementationclass>
<Style> wrapped </style>
<Use> literal </use>
<Scope> application </scope>
</Service>

Our web service name is helloworldservice, the interface is ihelloworldservice, and the Implementation class is helloworldserviceimpl.Note that the three steps can be completed in one step. You only need to use the new Web Service Wizard of myeclipse.


3. Then deploy the project to Tomcat through http: // localhost: 8081/helloworld/services/helloworldservice? The generated WSDL file is displayed in the WSDL file. Note that after deployment, services will be copied to the WEB-INF/classes/META-INF/xfire directory, xfire will automatically search for this directory and load the configuration file. You can write a client to test the web service, or click launch the Web Services on myeclipse to test the web service.

4. Compile the client code:

Package net. rubyeye. webservicedemo;

Import java.net. malformedurlexception;
Import java. util. arraylist;
Import java. util. List;

Import org. codehaus. xfire. xfirefactory;
Import org. codehaus. xfire. Client. xfireproxyfactory;
Import org. codehaus. xfire. Service. Service;
Import org. codehaus. xfire. Service. Binding. objectservicefactory;

Public class helloworldclient {
Public static void main (string ARGs []) {
Service srvcmodel = new objectservicefactory ()
. Create (ihelloworldservice. Class );
Xfireproxyfactory factory = new xfireproxyfactory (xfirefactory
. Newinstance (). getxfire ());

String helloworldurl = "http: // localhost: 8081/helloworld/services/helloworldservice ";
Try {
Ihelloworldservice srvc = (ihelloworldservice) Factory. Create (
Srvcmodel, helloworldurl );
System. Out. Print (srvc. sayhello ("Dennis "));
} Catch (malformedurlexception e ){
E. printstacktrace ();
}

}
}

Run and print: Hello, Dennis

Note: You can also use the new WebService client Wizard of myeclipse to automatically generate the client and the stub class for the client to call.

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.