JBoss Development Web Service
Author: kongxx
Configure
Use JBoss version
3.2.3
.
JBoss.net is a module for providing Web Service to build on Axis projects in Apache. Usually we do not include JBoss.net services in "Default" Server, but is included in "All" Server. So if you need to use Web Service, you need to use "All" Server, or create a new Server to provide Web Service.
Create a directory (such as: kongxx) in $ jboss_home / server /, then copy all the files under the jboss_home / all to kongxx, start JBoss:
Run -c kongxx
After the JBoss is successful, use the browser to access http://192.168.0.201:8080/jboss-Net/services, the following page appears:
At this time, the configuration has been successful.
Develop Web Service
JBoss introduced a framework type -Web Service Archive (WSR) - to develop and deploy Web Service. WSR is actually a JAR file.
Write a Java file
Create a Java file and compile,
Public class helloworld {public string getMessage (String name) {return "Hello World," Name;}}
Create a description file
Create a meta-inflica in the directory where the HelloWorld.java file is located, and create a web-service.xml file in the meta-inflicity. The content is as follows:
XMLns = "http://xml.apache.org/axis/wsdd/" XMLns: xsi = "http://www.w3.org/2000/10/xmlschema-instance" XMLns: java = "http://xml.apache.org/axis/wsdd/providers/java"> service> deployment> Create a WSR file Enter the directory where helloWorld.java file and meta-inflicity are running, run JAR CVF HelloWorld.wsr HelloWorld.class Meta-INF A HelloWorld.WSR file is generated in the directory. Deploy Web Service Copy the HelloWorld.WSR file to $ bjoss_home / server / kongxx / deploy / under this, check the JBoss console, the following information will appear: 01: 37: 16,322 INFO [MainDeployer] Starting deployment of package: file: /usr/local/jboss3x/server/kongxx/deploy/HelloWorld.wsr 01: 37: 16,411 INFO [MainDeployer] Deployed package: file: / usr / local /jboss3x/server/kongxx/deploy/helloWorld.WSR This time you visit http://192.168.0.201:8080/jboss-Net/services in your browser, appears: It has a Web Service that contains HelloWorld, and the description has been deployed successfully. Test Web Service Java test Create a test client, the code is as follows: import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode Public class testclient {public static void main (String [] args) {Try {string endpoint = "http:8080/jboss-net/services/helloworld"; service service = new service (); Call call = (Call) service.createCall (); call.setTargetEndpointAddress (new java.net.URL (endpoint)); call.setOperationName ( "getMessage"); call.addParameter ( "name", XMLType.XSD_STRING, ParameterMode.IN ); Call.se.xsd_string; string return (new object [] {"kongxx"}); system.out.println ("Result:" RET);} catch (Exception) e) {system.err.println (e.tostring ());}}} Compile and run, output the following results: Result: Hello World, Kongxx Indicates that the Web Service is running correctly. .NET test Create a new project, then Resolve the project name in the Program Explorer, select the Add Web reference in the right-click pop-up menu, as shown below: The following windows are popped up: Enter http://192.168.0.201:8080/jboss-net/services/helloworld?wsdl in the URL in the above window and press Go button to display the following information: Then press the Add Reference button to complete the reference. Add test code: WebReference.HelloworldService Service = new WebReference.helloWorldService (); console.writeline (Service.getMessage ("kongxx")); run output: Hello World, KONGXX show Web service Run correct.