i) install SOAP UI Plugin for Eclipise
http://www.soapui.org/eclipse/update/site.xml
ii) Create a new project for the HelloSeriveClient (Java Project)
iii) Select the project and Right Click->Soap UI->Add SOAPUI Nature, SOAP UI WebService item will be added
iv) Select SOAP UI perspective
Right click on Projects->hellowworlclient->Add WSDL from URL, enter the deployed service URL: http://localhost:8080/HelloService/Hello?wsdl. This will import the wsdl and you will see HelloPortBinding
v)Select HelloPortBinding and Right Click->GenerateCode->JAX-WS Artifacts
Enter the appropriate info in the JAX-WS Artifacts window
vi) Click Tools and enter the location of JAX-WS Wsimport.bat file.
* if you are using Java6 create the wsimport.bat file (only wsimport.exe file is available in Java 6, but soapUI plugin expects wsimport.bat file)
@echo off
setlocal
call wsimport.exe %1 %2 %3 %4 %5 %6 %7 %8 %9"
endlocal
vii) Click OK
viii) Then click Generate on JAX-WS Artifacts window, it will display dialog box the operation was successful. Switch back to Java Perspective, then refresh the src folder and you can see the wsimport generated classes.
ix) Now you implement HelloServiceClient code.
package test;
import mypackage.Hello;
import mypackage.HelloService;
public class TestHelloService {
/**
* @param args
*/
public static void main(String[] args) {
// Create Service
HelloService service = new HelloService();
//create proxy
Hello proxy = service.getHelloPort();
//invoke
System.out.println(proxy.sayHello("srini"));
}
}
Wednesday, 17 December 2008
Friday, 12 December 2008
Create your First Web Service Application using JAXWS
NetBeans Environment:
i) Create a new java Web Project name it "HelloService"
ii) create a new java class "Hello.java" and Add "@WebService" annotation at the top of the class
@WebService
public class Hello {
public String sayHello(String name) {
return "Hello " + name ;
}
}
iii) Deploy your application
right click the project and Deploy
That's it.. Your first web service application is ready.
Eclipse Evnironment:
i)Create the Dynamic Web Project "HelloService"
ii) web.xml
------------
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
iii) sun-jaxws.xml (create under WEB-INF folder )
<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0"
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint implementation="mypackage.Hello" name="Hello"
url-pattern="/Hello" />
</endpoints>
iv) Copy all the jaxws api files into the WEB-INF\lib folder
v) Create the same Hello.java file (copy the code from step ii - webservices - netbeans setup)
vi) Run this application from Eclipise
Now you can view your service from the following url.
http://localhost:8080/HelloService/Hello
i) Create a new java Web Project name it "HelloService"
ii) create a new java class "Hello.java" and Add "@WebService" annotation at the top of the class
@WebService
public class Hello {
public String sayHello(String name) {
return "Hello " + name ;
}
}
iii) Deploy your application
right click the project and Deploy
That's it.. Your first web service application is ready.
Eclipse Evnironment:
i)Create the Dynamic Web Project "HelloService"
ii) web.xml
------------
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
iii) sun-jaxws.xml (create under WEB-INF folder )
<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0"
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint implementation="mypackage.Hello" name="Hello"
url-pattern="/Hello" />
</endpoints>
iv) Copy all the jaxws api files into the WEB-INF\lib folder
v) Create the same Hello.java file (copy the code from step ii - webservices - netbeans setup)
vi) Run this application from Eclipise
Now you can view your service from the following url.
http://localhost:8080/HelloService/Hello
Labels:
JAXWS,
web service
Subscribe to:
Posts (Atom)