A simple example of WebService development using eclipse

Source: Internet
Author: User
Download the axis package first
: Http://ws.apache.org/axis/

Create a web project named Axis

Copy all files in the webapps/axis directory of the Axis package to the webroot directory of the project directory, and refresh the project

Create a new Java file named helloclient. The file content is as follows:
Public class helloclient <br/>{< br/> Public String getname (string name) <br/>{< br/> return "hello" + name; <br/>}< br/>
Now copy helloclient. Java to the webroot directory and rename it helloclient. JWS.

Deploy the project and start the service

Start the browser and open the following link
Http: // localhost/axis/helloclient. JWS? WSDL
If you have not configured a server port, use the following address:
Http: // localhost: 8080/axis/helloclient. JWS? WSDL

If it is normal, an XML file as follows will be displayed:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/>-<WSDL: Definitions targetnamespace = "http: // localhost: 8080/axis/helloclient. JWS "xmlns: apachesoap =" http://xml.apache.org/xml-soap "xmlns: impl =" http: // localhost: 8080/axis/helloclient. JWS "xmlns: INTF =" http: // localhost: 8080/axis/helloclient. JWS "xmlns: soapenc =" http://schemas.xmlsoap.org/soap/encoding/ "xmlns: WSDL =" http://schemas.xmlsoap.org/wsdl/ "xmlns: wsdlsoap =" http://schemas.xmlsoap.org/wsdl/ Soap/"xmlns: XSD =" http://www.w3.org/2001/XMLSchema "> <br/>-<! -- WSDL created by Apache axis version: 1.4 built on Apr 22,200 6 (06:55:48 PDT) <br/> -->-<WSDL: message name = "getnamerequest"> <br/> <WSDL: part name = "name" type = "XSD: string"/> <br/> </WSDL: message> <br/>-<WSDL: Message name = "getnameresponse"> <br/> <WSDL: part name = "getnamereturn" type = "XSD: string "/> <br/> </WSDL: Message> <br/>-<WSDL: porttype name =" helloclient "> <br/>-<WSDL: operation name = "getname" parameterorder = "name"> <br/> <WSDL: input message = "impl: getnamerequest "name =" getnamerequest "/> <br/> <WSDL: Output Message =" impl: getnameresponse "name =" getnameresponse "/> <br/> </WSDL: operation> <br/> </WSDL: porttype> <br/>-<WSDL: Binding name = "helloclientsoapbinding" type = "impl: helloclient "> <br/> <wsdlsoap: Binding style =" RPC "mce_style =" RPC "Transport =" http://schemas.xmlsoap.org/soap/http "/> <br/>-<WSDL: operation name = "getname"> <br/> <wsdlsoap: Operation soapaction = ""/> <br/>-<WSDL: input name = "getnamerequest"> <br/> <wsdlsoap: Body encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/" namespace = "http: // defaultnamespace "use =" encoded "/> <br/> </WSDL: input> <br/>-<WSDL: output name = "getnameresponse"> <br/> <wsdlsoap: Body encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/" namespace = "http: // localhost: 8080/axis/helloclient. JWS "use =" encoded "/> <br/> </WSDL: output> <br/> </WSDL: Operation> <br/> </WSDL: binding> <br/>-<WSDL: Service name = "helloclientservice"> <br/>-<WSDL: Port binding = "impl: helloclientsoapbinding "name =" helloclient "> <br/> <wsdlsoap: address location =" http: // localhost: 8080/axis/helloclient. JWS "/> <br/> </WSDL: Port> <br/> </WSDL: Service> <br/> </WSDL: Definitions> <br/>

Create a new test class: helloclienttest. java. The Code is as follows:
Import javax. XML. namespace. QNAME; <br/> Import Org. apache. axis. client. call; <br/> Import Org. apache. axis. client. service; </P> <p> public class testhelloclient {</P> <p> Public static void main (string [] ARGs) {<br/> try {<br/> string endpoint = "http: // localhost/axis/helloclient. JWS "; <br/> service = new service (); <br/> call = NULL; <br/> call = (CALL) service. createcall (); <br/> call. setoperationname (New QNAME (<br/> "http: // localhost/axis/helloclient. JWS "," getname "); <br/> call. settargetendpointaddress (New java.net. URL (endpoint); <br/> string STR = (string) Call. invoke (new object [] {"Sonic"}); <br/> system. out. println (STR); <br/>} catch (exception ex) {<br/> ex. printstacktrace (); <br/>}< br/>}
Okay, you can test it!

Related Article

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.