1. Create an exploded WAR in the 4.0.4.GA w/EJB3 &147;deploy&148; directory.
2. Create sub-directories: WEB-INF\classes\org\jboss\samples
3. Create the webservice interface called HelloWorldInterface.java:
package org.jboss.samples; import java.rmi.Remote; public interface HelloWorldInterface extends Remote { public String sayHello(String toWhom); }
4. Create the annotated WS 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 implements HelloWorldInterface { @WebMethod public String sayHello(String toWhom) { System.out.println("I'm Hit! " + toWhom); return "Hello World: " + toWhom + " on " + new java.util.Date(); } }
Note: @SOAPBinding is optional, targetNamespace is also optional
5. Compile using Java 5 with this CLASSPATH:
set JBOSS_HOME=C:\JBoss\jboss-4.0.4.GA
set CLASSPATH=.;%JBOSS_HOME%\server\default\deploy\jbossws.sar\jbossws.jar
6. Create a web.xml file in the WEB-INF directory with the following:
<?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>
7. Using your browser hit: http://localhost:8080/jbossws and click on View
8. You should see a listing with http://yourhost:8080/MyWS/HelloWorldService?wsdl where &147;MyWS&148; was the name of the exploded WAR directory created in Step 1. Click on the link to view the WSDL
9. For .NET Interop, download and install Microsoft Visual Basic Express Edition. Start a new Windows Application project. Add a Web Reference to the URL listed in step 7.
Dim proxy As New JBossHelloWorld.HelloWorldWSService Dim result As String result = proxy.sayHello(TextBox1.Text) MsgBox(result)
Note: where JBossHelloWorld was the name given while adding the Web Reference
Some Gotchas with this simple receipe:
Tip: In the @WebMethod annotation for the sayHello method add (operationName=&147;SayHello&148;) as this will produce proxy.SayHello() on the VB side. A .NET person expects to have their method/function names begin with a capital letter.
Trick: For an exploded WAR, JBossWS 1.0 copies your web.xml to web.xml.org and creates its own web.xml. This web.xml fails to redeploy when the AppServer boots up or when &147;touched&148;, simply delete and rename web.xml.org back to web.xml.
Trick: Collections not currently supported, use Arrays (this will be addressed soon)
Trick: Really complex objects might be problematic (this will be addressed soon). If you use Document instead of RPC (doc is the default) you&146;ll need to know how to tweak the WSDL
Tip: This recipe doesn&146;t provide you with the Java client-side which would be useful for automated unit testing. When you have the basic working, build an Ant script similar to the ones in the JBossWS samples.
Tip: Do consider the use of NAnt and NUnit for automated building/integration and unit testing on the .NET side.
Comments