This tutorial is for windows Users.
D:\>md jcode
D:\jcode>md ws-server
D:\jcode\ws-server>notepad HelloWorldWS.java
Paste the Below Code in notepad and Save.
package org.example.webservice; import javax.jws.*; import javax.xml.ws.Endpoint; @WebService public class HelloWorldWS{ public String echo(String name) { return "HI ! ,"+name; } public static void main(String args[]){ Endpoint.publish("http://localhost:8080/HelloWorldWS",new HelloWorldWS()); } }
The url along with the port can be changed to include ur ip address, so that it can be remotely accessed.
D:\jcode\ws-server>javac HelloWorldWS.java
D:\jcode\ws-server>md org
D:\jcode\ws-server>md org\exampleD:\jcode>md org\example\webservice
D:\jcode\ws-server>copy HelloWorldWS.class org\example\webservice
D:\jcode\ws-server>java org.example.webservice.HelloWorldWS
Keep this running. Now open another cmd window.
Also you can Check the WSDL from your browser, which will be consumed by the client, with the following link.
http://localhost:8080/HelloWorldWS?wsdl
D:\jcode\ws-server>cd ..
D:\jcode>md wsclient
D:\jcode>wsimport -s wsclient http://localhost:8080/HelloWorldWS?wsdl
D:\jcode>notepad wsclient\WSClient.java
Paste the Below Code in notepad and Save.
package wsclient; import org.example.webservice.*; public class WSClient { public static void main(String args[]){ HelloWorldWS obj = (new HelloWorldWSService()).getHelloWorldWSPort(); System.out.println(obj.echo(" World ")); } }
D:\jcode>javac wsclient/WSClient.java
D:\jcode>java -Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.
dump=true wsclient.WSClient
---[HTTP request - http://localhost:8080/HelloWorldWS]---
Content-type: text/xml;charset="utf-8"
Soapaction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2,
*/*; q=.2
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envel
ope/"><S:Body><ns2:echo xmlns:ns2="http://webservice.example.org/"><arg0> World
</arg0></ns2:echo></S:Body></S:Envelope>--------------------
---[HTTP response - http://localhost:8080 /HelloWorldWS - 200]---
Transfer-encoding: chunked
null: HTTP/1.1 200 OK
Content-type: text/xml;charset="utf-8"
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envel
ope/"><S:Body><ns2:echoResponse xmlns:ns2="http://webservice.example.org/"><retu
rn>HI ! , World </return></ns2:echoResponse></S:Body></S:Envelope>--------------
------
HI ! , World
SOAP REQUEST GENERATED :
<?xml version="1.0" ?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:echo xmlns:ns2="http://webservice.example.org/"> <arg0>World</arg0> </ns2:echo> </S:Body> </S:Envelope>
SOAP RESPONSE GENERATED :
<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:echoResponse xmlns:ns2="http://webservice.example.org/">
<return>HI ! ,World</return>
</ns2:echoResponse>
</S:Body>
</S:Envelope>
No comments:
Post a Comment