JAX-WS Webservice Hello World Example
Author : Ishtek

Yet another Hello World Example on JAX-WS webservice:

I have tried to keep it simple by defining step by step aproach for coding and
deploying a Webservice using JAX-WS, onto an instance of JBoss Application server (Standalone type).

Once the WAR file that is created by using this example files, we can deploy it by placing
this WAR file under %JBOSS_HOME%/standalone/deployments folder.
If you see console output something like as shown below, then it means this example webservice
is properly deployed in the application server runtime.

..: Starting deployment of "helloworld.war" .. Add Service id=net.techiecommunity.HelloWorldPortTypeImpl address=http://localhost:8080/helloworld/HelloWorldService implementor=net.techiecommunity.HelloWorldPortTypeImpl invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker serviceName={http://www.techiecommunity.net/}HelloWorldService portName={http://www.techiecommunity.net/}HelloWorldPort wsdlLocation=null mtomEnabled=false .. Creating Service {http://www.techiecommunity.net/}HelloWorldService from WSDL: /WEB-INF/wsdl/HelloWorldWS.wsdl .. Setting new service endpoint address in wsdl: http://localhost:8080/HelloWorld/HelloWorldService .. Setting new service endpoint address in wsdl: http://localhost:8080/helloworld/HelloWorldService .. Setting the server's publish address to be http://localhost:8080/helloworld/HelloWorldService .. WSDL published to: file:/D:/jboss-as-7.1.1.Final/standalone/data/wsdl/helloworld.war/HelloWorldWS.wsdl .. Starting service jboss.ws.endpoint."helloworld.war"."net.techiecommunity.HelloWorldPortTypeImpl" .. register: jboss.ws:context=helloworld,endpoint=net.techiecommunity.HelloWorldPortTypeImpl .. Registering web context: /helloworld ..: Deployed "helloworld.war"
I have started this example by creating this example WSDL file as shown below:

<?xml version="1.0" encoding="utf-8"?> <definitions name="HelloWorldWS" targetNamespace="http://www.techiecommunity.net/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.techiecommunity.net/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <message name="HelloWorldRequest"> <part name="nameTxt" type="xsd:string"/> </message> <message name="HelloWorldResponse"> <part name="greeting" type="xsd:string"/> </message> <portType name="HelloWorldPortType"> <operation name="sayHelloWorld"> <input message="tns:HelloWorldRequest"/> <output message="tns:HelloWorldResponse"/> </operation> </portType> <binding name="HelloWorldBinding" type="tns:HelloWorldPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="sayHelloWorld"> <soap:operation soapAction="sayHelloWorld"/> <input> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:net:techiecommunity" /> </input> <output> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:net:techiecommunity" /> </output> </operation> </binding> <service name="HelloWorldService"> <port binding="tns:HelloWorldBinding" name="HelloWorldPort"> <soap:address location="http://localhost:8080/HelloWorld/HelloWorldService"/> </port> </service> </definitions>

Then I used wsimport command line program to create various generated files as shown below: HelloWorldService/WEB-INF/classes/net/techiecommunity/HelloWorldPortType.java

package net.techiecommunity; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; /** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.2.4-b01 * Generated source version: 2.2 * */ @WebService(name = "HelloWorldPortType", targetNamespace = "http://www.techiecommunity.net/") @SOAPBinding(style = SOAPBinding.Style.RPC) public interface HelloWorldPortType { /** * * @param nameTxt * @return * returns java.lang.String */ @WebMethod(action = "sayHelloWorld") @WebResult(name = "greeting", partName = "greeting") public String sayHelloWorld( @WebParam(name = "nameTxt", partName = "nameTxt") String nameTxt); }

After generating all the Java files along with implementing the interface "HelloWorldPortType" and filling out the method imlementation as shown below:

package net.techiecommunity; import javax.jws.WebMethod; import javax.jws.WebService; @WebService(serviceName = "HelloWorldService", targetNamespace = "http://www.techiecommunity.net/", portName = "HelloWorldPort", wsdlLocation = "/WEB-INF/wsdl/HelloWorldWS.wsdl", endpointInterface = "net.techiecommunity.HelloWorldPortType") public class HelloWorldPortTypeImpl implements HelloWorldPortType { @WebMethod public String sayHelloWorld(String name) { return "Hello ... "+name; } }


package net.techiecommunity; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.WebEndpoint; import javax.xml.ws.WebServiceClient; import javax.xml.ws.WebServiceException; import javax.xml.ws.WebServiceFeature; /** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.2.4-b01 * Generated source version: 2.2 * */ @WebServiceClient(name = "HelloWorldService", targetNamespace = "http://www.techiecommunity.net/", wsdlLocation = "http://localhost:8080/HelloWorld/HelloWorldService?wsdl") public class HelloWorldService extends Service { private final static URL HELLOWORLDSERVICE_WSDL_LOCATION; private final static WebServiceException HELLOWORLDSERVICE_EXCEPTION; private final static QName HELLOWORLDSERVICE_QNAME = new QName("http://www.techiecommunity.net/", "HelloWorldService"); static { URL url = null; WebServiceException e = null; try { url = new URL("http://localhost:8080/HelloWorld/HelloWorldService?wsdl"); } catch (MalformedURLException ex) { e = new WebServiceException(ex); } HELLOWORLDSERVICE_WSDL_LOCATION = url; HELLOWORLDSERVICE_EXCEPTION = e; } public HelloWorldService() { super(__getWsdlLocation(), HELLOWORLDSERVICE_QNAME); } public HelloWorldService(WebServiceFeature... features) { super(__getWsdlLocation(), HELLOWORLDSERVICE_QNAME, features); } public HelloWorldService(URL wsdlLocation) { super(wsdlLocation, HELLOWORLDSERVICE_QNAME); } public HelloWorldService(URL wsdlLocation, WebServiceFeature... features) { super(wsdlLocation, HELLOWORLDSERVICE_QNAME, features); } public HelloWorldService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public HelloWorldService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { super(wsdlLocation, serviceName, features); } /** * * @return * returns HelloWorldPortType */ @WebEndpoint(name = "HelloWorldPort") public HelloWorldPortType getHelloWorldPort() { return super.getPort(new QName("http://www.techiecommunity.net/", "HelloWorldPort"), HelloWorldPortType.class); } /** * * @param features * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. * @return * returns HelloWorldPortType */ @WebEndpoint(name = "HelloWorldPort") public HelloWorldPortType getHelloWorldPort(WebServiceFeature... features) { return super.getPort(new QName("http://www.techiecommunity.net/", "HelloWorldPort"), HelloWorldPortType.class, features); } private static URL __getWsdlLocation() { if (HELLOWORLDSERVICE_EXCEPTION!= null) { throw HELLOWORLDSERVICE_EXCEPTION; } return HELLOWORLDSERVICE_WSDL_LOCATION; } }

Now all the files should be placed in appropriate folders as per WAR file structure. Now create a WAR file using command like:
war cvf helloworldws.war *
And placing this WAR file inside %JBOSS_HOME%/standalone/deployments folder and start JBoss Application Server instance by using the command found under %JBOSS_HOME%/bin/standalone.bat in Microsoft Windows OS environment. If you come across any technical defficulties, if interested, can discuss it here by using following form.
If interested in commenting related to JAX-WS Webservice Hello World Example
Click Here

Name (To be shown on this Page:*

Email (Not to be shown):*

Website (To be shown on this Page)

Your Comments here (To be shown on this Page):*

(You can use <a> Tag in your comments)

Please enter same number as shown here 997

Name: GirishDated: 2014-01-05 13:54:15
Can you help in finding some reasonable approach for solving security related code
while using webservices using JAX-WS?

Thanks for help!!    
Click Here

Name (To be shown on Page):*

Email (Optional): (never shown)

Website (To be shown on this Page)

Your Comments here (To be shown on Page):*

Please enter same number as shown here 507

Android Thread Example

REST Interview Questions

JAX-WS Webservice Example

Android Overlap SurfaceView Example

Spring3 Integration of File Endpoint

JAXWS Webservice Example

Android WebView Example

Android Context Menu Example

Setting up Eclipse for Android App Development

Android SensorEvent Orientation Example

Android ImageSwitcher Example

REST API Design for Android App

Android ExpandableListView Example

Singleton Serializable on Android

Android GPS with Google MAP Example

Android Project With Example

Android Project Manageing Files

Project Ideas for App on Android Platform

Android EditText with Background

Android SQLite Database Example

Android AutoCompleteTextView Example

Android Tester

Android Interview Questions

Android ListView Example

Android Intent Notification Example

Android Intent Broadcast Example

Android TextView Link Example

Android Sensor List

Android Sensor Orientation Example

Android Intent Broadcast Receiver

Android Gallery SurfaceViews Example

Android Location Example

Android Text to Speech Example

Android Intent Example

Android Layout Example

Android Download File Example

Android Expandable ListView Example

Android Tab Example

Android RelativeLayout Example

Android Intent Example

Android Text to Speech Example

Android SQLite Example

Android CustomView Example

Android Canvas Example

Android SharedPreferences Example

Android Shape Background Example

Android ShapeButton Example

Android ViewFlipper Example

Android Gallery Example

Android TimePickerDialog Example

The content provided in this page is NOT warranted and/or NOT guaranteed by techiecommunity.net .
techiecommunity.net is not liable for any negative consequences that may result/arise from 
implementing directly/indirectly any information covered in these pages/articles/tutorials.

For any of the content, if you would like to bring it to notice for removal from this web site, 
please write to this web site administrator @ EMAIL-ID (please remove space before and after @),
with appropriate concern and supporting proof(s). After thorough review and if found genuine concern,
we would take appropriate action and remove disputed content from this web site within 24 hours 
starting from the time it has brought to techiecommunity.net Administrator notice.

While using this web site, you agree to have read and accepted techiecommunity.net terms of use and privacy policy.
This website uses cookies to improve the user experience and gather statistics. Our advertisers use cookies too (3rd party cookies), to provide more relevant ads. Continued use of this website implies that you accept the use of cookies on this website.