Follow below simple steps to create and deploy simple Web Service
and Web Service Client
in Eclipse IDE.
Step-1
Install Apache Tomcat and add it to Eclipse in Server Tab – I’m using Tomcat version 9.0.10
.
Step-2
Create a Dynamic Web Project (name: CrunchifyWS
)
Step-3
Create java file under /src
folder. Right Click /src folder -> New -> Class.
- Package:
crunchify.com.web.service
- Name:
CrunchifyHelloWorld.java
Step-4
Open CrunchifyHelloWorld.java
file and create simple main method.
package crunchify.com.web.service; /** * @author Crunchify.com */ public class CrunchifyHelloWorld { public float addValue(float value) { return (value + 10); } public float subtractValue(float value) { return (value - 10); } }
Step-5
- Right Click on file
CrunchifyHelloWorld.java -> Web Services -> Create Web Service
- Select options as mentioned in below diagram.
- Click finish
Step-6
It may take some time to finish all processes and you should see new project “CrunchifyWSClient
” created. Here is a final project structure:
Step-7
CrunchifyWS
and CrunchifyWSClient
both projects should be automatically deployed to server.
Also, Eclipse automatically opens Web Service Test Client Window
with URL: http://localhost:8080/CrunchifyWSClient/sampleCrunchifyHelloWorldProxy/TestClient.jsp?endpoint=http://localhost:5922/CrunchifyWS/services/CrunchifyHelloWorld
Step-8
Now click on addValue(float)
, subtractValue(float)
and provide an input to check updated result.
And you are all set. Do let me know if you see any difficulty with these steps.
Are you getting below error after clicking Invoke button?
Result Exception: java.net.ConnectException: Connection refused (Connection refused) Message: ; nested exception is: java.net.ConnectException: Connection refused (Connection refused)
Follow below steps:
- Right click on Tomcat
- Click Add and Remove to see application added
- Click Clean…
- Click Publish
- Click Restart
How to rerun WebService after restarting Application or later?
Here is a handy URL: http://localhost:8080/CrunchifyWSClient/sampleCrunchifyHelloWorldProxy/TestClient.jsp
If you want to download CrunchifyHelloWorld.wsdl then here it is:
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://service.web.com.crunchify" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://service.web.com.crunchify" xmlns:intf="http://service.web.com.crunchify" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)--> <wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://service.web.com.crunchify" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="subtractValue"> <complexType> <sequence> <element name="value" type="xsd:float"/> </sequence> </complexType> </element> <element name="subtractValueResponse"> <complexType> <sequence> <element name="subtractValueReturn" type="xsd:float"/> </sequence> </complexType> </element> <element name="addValue"> <complexType> <sequence> <element name="value" type="xsd:float"/> </sequence> </complexType> </element> <element name="addValueResponse"> <complexType> <sequence> <element name="addValueReturn" type="xsd:float"/> </sequence> </complexType> </element> </schema> </wsdl:types> <wsdl:message name="subtractValueResponse"> <wsdl:part element="impl:subtractValueResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="addValueResponse"> <wsdl:part element="impl:addValueResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="addValueRequest"> <wsdl:part element="impl:addValue" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="subtractValueRequest"> <wsdl:part element="impl:subtractValue" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="CrunchifyHelloWorld"> <wsdl:operation name="subtractValue"> <wsdl:input message="impl:subtractValueRequest" name="subtractValueRequest"> </wsdl:input> <wsdl:output message="impl:subtractValueResponse" name="subtractValueResponse"> </wsdl:output> </wsdl:operation> <wsdl:operation name="addValue"> <wsdl:input message="impl:addValueRequest" name="addValueRequest"> </wsdl:input> <wsdl:output message="impl:addValueResponse" name="addValueResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CrunchifyHelloWorldSoapBinding" type="impl:CrunchifyHelloWorld"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="subtractValue"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="subtractValueRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="subtractValueResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="addValue"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="addValueRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="addValueResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="CrunchifyHelloWorldService"> <wsdl:port binding="impl:CrunchifyHelloWorldSoapBinding" name="CrunchifyHelloWorld"> <wsdlsoap:address location="http://localhost:8080/CrunchifyWS/services/CrunchifyHelloWorld"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Let me know if you face any issue running this.