JSR181 Annotated Web Services Intro
burrsutter May 3, 2006 5:11 PMHello,
I'm trying to find the fastest and easiest way to deploy a JSR181-based Web Service on JBossWS 1.0GA and JBoss AppServer 4.0.4GA (built from source). My goal with this posting is to find out if others are interested in this Getting Started, HelloWorld approach.
Here is my process to make Hello World work:
1) Create a directory called MyWS.war in the default\deploy directory
2) Create the following directory structure under MyWS.war:
-- WEB-INF\classes\org\jboss\samples
3) Create the annotated Web Service called HelloWorldWS.java
package org.jboss.samples; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Use; @WebService(name = "HelloWorld", targetNamespace="http://com.burrsutter.jbossws/helloworld") @SOAPBinding(style = SOAPBinding.Style.RPC) public class HelloWorldWS { @WebMethod public String sayHello(String toWhom) { System.out.println("I'm Hit! " + toWhom); return "Aloha " + toWhom + " on " + new java.util.Date(); } }
4) Use the Java 5 compiler to compile HelloWorldWS.java to HelloWorldWS.class. Here is my classpath to pull off this trick, you'll wish to modify for your JBOSS_HOME:
set JBOSS_HOME=C:\JBoss\wsdemo4\jboss-4.0.x\build\output\jboss-4.0.4.GA-ejb3 set CLASSPATH=%CLASSPATH%;%JBOSS_HOME%\server\default\deploy\jbossws.sar\jbossws.jar
5) Create a web.xml file in the WEB-INF folder with the following content:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>HelloWorldService</servlet-name> <servlet-class>org.jboss.samples.HelloWorldWS</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorldService</servlet-name> <url-pattern>/HelloWorldService</url-pattern> </servlet-mapping> </web-app>
6) In your browser hit: http://localhost:8080/jbossws and click on View the list of deployed Web Services
7) Click on http://yourhost:8080/MyWS/HelloWorldService?wsdl to view the WSDL.
DONE! This should be a wiki posting and I'll happily add it once there is some validation by the folks here.
I always try to use VB.NET as a consumer to prove the interop so I downloaded Visual Basic 2005 Express Edition and it hit the web service.
Here is the VB.NET code in case you are interested:
Make sure to add the Web Reference and point it to the url for the WSDL. Plus I added a TextBox and CommandButton to the WinForm.
This code is in the Button1_Click event delegate
Dim proxy As New JBossHelloWorld.HelloWorldWSService Dim result As String result = proxy.sayHello(TextBox1.Text) MsgBox(result)
I'm working on an Excel consumer example as well but that is giving me troubles at this moment.
Burr
burr.sutter@jboss.com