Development of Web service code based on Tomcat5.0 and AXIS2

Source: Internet
Author: User
Tags soap

1. What did HelloWorld do?

HelloWorld function is very simple, in the client input your name, in this case, ZJ. After the parameter is passed to the server, the processing will return name+ "helloworld!", in this case ZJ helloworld!

2. Server-side file Helloworld.java

Helloworld.java

package sample;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
public class HelloWorld {
   //读取client端getSayHelloOMElement()方法传递的参数in。
    public OMElement sayHello(OMElement in){
     //将in转换为String。
        String name=in.getText();
        String info=name+"HelloWorld!";
     //创建response SOAP包。
        OMFactory fac=OMAbstractFactory.getOMFactory();
     // OMNamespace指定此SOAP文档名称空间。
        OMNamespace omNs=fac.createOMNamespace("http://helloworld.com/","hw");
     //创建元素sayHello,并指定其在omNs指代的名称空间中。
        OMElement resp=fac.createOMElement("sayHelloResponse",omNs);
     //指定元素的文本内容。
        resp.setText(info);
        return resp;
    }
}

3. Services.xml Deployment Files

Services.xml

<?xml version="1.0" encoding="UTF-8"?>
//下面定义服务名
<service name="HelloWorld">
<description>
  This is a sample Web Service.
</description>
// ServiceClass指定Java Class的位置,即实现服务的类。
<parameter name="ServiceClass" locked="false">sample.HelloWorld</parameter>
// operation 与Java Class中方法名对应。
<operation name="sayHello">
// messageReceiver看下文注解。
  <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>

Annotation: Message exchange Mode.

Currently, AXIS2 supports three modes: In-only, robust-in and In-out. The IN-ONLY message exchange Mode is a SOAP request, not a response, a robust-in message exchange Mode that sends a SOAP request and returns an answer only if there is an error; in-out the message exchange Mode always has a SOAP request and an answer. This example uses In-out mode.

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.