JBoss Development Web Service [original]

Source: Internet
Author: User
Tags getmessage jboss

JBoss Development Web Service

Author: kongxx Configuration

Use the JBoss version <?xml:namespace prefix = st1 ns = "Urn:schemas-microsoft-com:office:smarttags"/>3.2.3.

Jboss.net is a module used to provide Web service, built on the axis project of Apache. Typically, the "default" server we use does not include the Jboss.net service, but is included in the "All" server. Therefore, if you need to use a Web service, you need to use the "all" server, or create a new server to provide the Web service.

Under $jboss_home/server/, create a new directory (such as: KONGXX), and then copy all files under $jboss_home/all to Kongxx, and use the command to start JBOSS:

Run–c kongxx

When JBoss succeeds and the browser accesses http://192.168.0.201:8080/jboss-net/services, the following page appears:

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml"/><?xml:namespace prefix = o ns = "Urn:schemas-mi" Crosoft-com:office:office "/>

This indicates that the configuration was successful. Developing web Service

JBoss introduced a framework type-web Service Archive (WSR)-to develop and deploy WEB service. WSR is actually a jar file. Writing Java files

Create a Java file and compile it,

public class helloworld{

public string GetMessage (string name) {

Return "Hello World," + name;

}

}

Create a description file

Create the Meta-inf directory in the directory where the Helloworld.java file resides, and create a web-service.xml file under the Meta-inf directory, as follows:

<deployment

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 name= "HelloWorld" provider= "Java:rpc" >

<parameter name= "ClassName" value= "HelloWorld"/>

<parameter name= "Allowedmethods" value= "GetMessage"/>

</service>

</deployment>

Creating WSR Files

Enter the directory of the Helloworld.java file and Meta-inf directory, run

Jar CVF HELLOWORLD.WSR Helloworld.class meta-inf

A HELLOWORLD.WSR file is generated in the directory at this time. Deploying Web Service

When you copy the Helloworld.wsr file to $bjoss_home/server/kongxx/deploy/, and then view the JBoss console, you receive the following message:

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

At this point in the browser to access http://192.168.0.201:8080/jboss-net/services, the following page appears:

It already contains the HelloWorld Web Service, which indicates that the deployment was successful. Test Web Service Java Test

Create a test client with the following code:

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://192.168.0.201: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.setreturntype (xmltype.xsd_string);

string ret = (string) call.invoke (new Object [] {"kongxx"});

SYSTEM.OUT.PRINTLN ("Result:" + ret);

catch (Exception e) {

System.err.println (E.tostring ());

}

}

}

Compile and run to output the following results:

Result:hello World, Kongxx

Indicates that the Web service is running correctly. . NET Test

Create a new project, then the project name in Solution Explorer, and in the right-click pop-up menu, select Add a Web reference, as shown in the following figure:

The following window pops up:

Enter HTTP://192.168.0.201:8080/JBOSS-NET/SERVICES/HELLOWORLD?WSDL in the URL in the above window and press the Go button to display the following information:

Then press the Add Reference button to complete the reference.

To add a test code:

Webreference.helloworldservice service = new Webreference.helloworldservice ();

Console.WriteLine (Service.getmessage ("kongxx"));

Run after output:

Hello World, Kongxx

Indicates that the Web service is running correctly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.