阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

基于Myeclipse+Axis2的WebService开发实录

458次阅读
没有评论

共计 7816 个字符,预计需要花费 20 分钟才能阅读完成。

最近开始学习了下在 Myeclipse 开发工具下基于 WebSerivce 的开发,下面将相关相关关键信息予以记录

1.Myeclipse 的安装,本文以 Myeclipse2014-blue 为开发环境,相关配置执行完善

2. 从 http://archive.apache.org/dist/ws/axis2/tools/ 下载 Axis2 包, 下载 axis2-eclipse-codegen-wizard.zip, 下载 axis2-eclipse-service-archiver-wizard.zip

3. 从 http://axis.apache.org/axis2/java/core/download.html 下载 (axis2-1.7.0-bin.zip,axis2-1.7.0-war.zip,axis2-eclipse-codegen-plugin-1.7.0.zip,axis2-eclipse-service-plugin-1.7.0.zip)

4. 下载说明:从步骤 1 下载出来的 Axis2_Codegen_Wizard_1.3.0 文件夹,Axis2_Service_Archiver_1.3.0 文件夹拷贝到 myeclipse 安装目录之 dropins 文件下,重启 myeclipse 下载到的 axis2-1.7.0-war.zip,拷贝文件之 tomact/webapps 目录下面, 重命名 axis2.war, 刷新文件夹,tomact 为解压该部署包,此时可以通过 tomact 服务访问 axis2 站,看到相关页面表示成功

5. 在步骤 4 中,注意文件夹 axis2\WEB-INF,下面有 3 个文件夹,conf,modules,services,lib 文件夹,稍后我们会用到

6. 下面借助于 axis2 来开发 webservice

7. 打开 myeclipse 新建 web project 项目,将步骤 5 中 conf,modules,services,lib 文件夹的拷贝之 WebRoot/WEB-INF/ 下面, 并在 WEB-INF 下面新建 Web.xml 文件,倘若 web.xml 存在则打开,添加以下代码配置 axis2

8.axis2 配置代码如下:

<!– 加载 Axis2 –> 

<servlet> 

    <servlet-name>AxisServlet</servlet-name> 

    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class> 

    <load-on-startup>1</load-on-startup> 

</servlet> 

<servlet-mapping> 

    <servlet-name>AxisServlet</servlet-name> 

    <url-pattern>/services/*</url-pattern> 

</servlet-mapping> 

9. 在 WEB-INF/services/ 下新建 Axis2Service/META-INF/ 目录,新建文件 services.xml, 添加如下 webservice 服务配置代码

    <!– HelloWorld 表示您的 WebService 服务名 –>

<service name=”HelloWorld” >

    <!– HelloWorld 表示您的 WebService 服务描述 –>

    <description> 

          HelloWorld  Service Example 

    </description> 

    <!– 这个必须是这个服务的类路径 –>

    <parameter name=”ServiceClass”>     

        cn.homily.action.HelloWorld

    </parameter> 

    <!– 这个是这个服务的方法名 –>

    <operation name=”getHello”>   

        <messageReceiver class=”org.apache.axis2.rpc.receivers.RPCMessageReceiver” />   

    </operation>   

    <operation name=”getWorld”>   

        <messageReceiver class=”org.apache.axis2.rpc.receivers.RPCMessageReceiver” />   

    </operation>   

    <operation name=”getHelloWorld”>   

    <!– 这里要注意,当没有返回值时才用 

    org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver,

    没有参数还是用 RPCMessageReceiver–> 

        <messageReceiver class=”org.apache.axis2.rpc.receivers.RPCMessageReceiver” />   

    </operation>

</service>

10. 在 src 包下面添加子包 cn.homily.action,添加 HelloWorld.java 文件, 其代码如下:

package cn.homily.action;

// 服务名

public class HelloWorld

{<br> // 服务方法

    public String getHello(String name)

    {

        return “Hello,” + name + “.”;

    }

    // 服务方法

    public String getWorld(String name)

    {

        return “World,” + name + “.”;

    }

    // 服务方法

    public String getHelloWorld()

    {

        return “Hello,World”;

    }

}

经过以上步骤,我们的 WebService 基本代码已经全了,现在看看实际效果。

11. 现在打包我们的 Web-Project,部署我们的 Web-Project 至 tomact, 现在我们运行,在浏览器输入如下地址 http://zgc-20150226yxm:8080/sayHello2Axis/services/HelloWorld?wsdl。如果在浏览器里面看到了以下代码,说明我们的 Web-Service 服务 Demo 开发完成。正确的页面效果如下:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<wsdl:definitions xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/” xmlns:ns1=”http://org.apache.axis2/xsd” xmlns:ns=”http://action.homily.cn” xmlns:xs=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/” xmlns:soap12=”http://schemas.xmlsoap.org/wsdl/soap12/” xmlns:http=”http://schemas.xmlsoap.org/wsdl/http/” xmlns:mime=”http://schemas.xmlsoap.org/wsdl/mime/” xmlns:wsaw=”http://www.w3.org/2006/05/addressing/wsdl” targetNamespace=”http://action.homily.cn”>

<wsdl:documentation>HelloWorld</wsdl:documentation>

<wsdl:types>…</wsdl:types>

<wsdl:message name=”getHelloRequest”>

<wsdl:part name=”parameters” element=”ns:getHello”/>

</wsdl:message>

<wsdl:message name=”getHelloResponse”>

<wsdl:part name=”parameters” element=”ns:getHelloResponse”/>

</wsdl:message>

<wsdl:message name=”getHelloWorldRequest”>

<wsdl:part name=”parameters” element=”ns:getHelloWorld”/>

</wsdl:message>

<wsdl:message name=”getHelloWorldResponse”>

<wsdl:part name=”parameters” element=”ns:getHelloWorldResponse”/>

</wsdl:message>

<wsdl:message name=”getWorldRequest”>

<wsdl:part name=”parameters” element=”ns:getWorld”/>

</wsdl:message>

<wsdl:message name=”getWorldResponse”>

<wsdl:part name=”parameters” element=”ns:getWorldResponse”/>

</wsdl:message>

<wsdl:portType name=”HelloWorldPortType”>

<wsdl:operation name=”getHello”>

<wsdl:input message=”ns:getHelloRequest” wsaw:Action=”urn:getHello”/>

<wsdl:output message=”ns:getHelloResponse” wsaw:Action=”urn:getHelloResponse”/>

</wsdl:operation>

<wsdl:operation name=”getHelloWorld”>

<wsdl:input message=”ns:getHelloWorldRequest” wsaw:Action=”urn:getHelloWorld”/>

<wsdl:output message=”ns:getHelloWorldResponse” wsaw:Action=”urn:getHelloWorldResponse”/>

</wsdl:operation>

<wsdl:operation name=”getWorld”>

<wsdl:input message=”ns:getWorldRequest” wsaw:Action=”urn:getWorld”/>

<wsdl:output message=”ns:getWorldResponse” wsaw:Action=”urn:getWorldResponse”/>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name=”HelloWorldSoap11Binding” type=”ns:HelloWorldPortType”>

<soap:binding transport=”http://schemas.xmlsoap.org/soap/http” style=”document”/>

<wsdl:operation name=”getHello”>

<soap:operation soapAction=”urn:getHello” style=”document”/>

<wsdl:input>

<soap:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getHelloWorld”>

<soap:operation soapAction=”urn:getHelloWorld” style=”document”/>

<wsdl:input>

<soap:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getWorld”>

<soap:operation soapAction=”urn:getWorld” style=”document”/>

<wsdl:input>

<soap:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:binding name=”HelloWorldSoap12Binding” type=”ns:HelloWorldPortType”>

<soap12:binding transport=”http://schemas.xmlsoap.org/soap/http” style=”document”/>

<wsdl:operation name=”getHello”>

<soap12:operation soapAction=”urn:getHello” style=”document”/>

<wsdl:input>

<soap12:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap12:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getHelloWorld”>

<soap12:operation soapAction=”urn:getHelloWorld” style=”document”/>

<wsdl:input>

<soap12:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap12:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getWorld”>

<soap12:operation soapAction=”urn:getWorld” style=”document”/>

<wsdl:input>

<soap12:body use=”literal”/>

</wsdl:input>

<wsdl:output>

<soap12:body use=”literal”/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:binding name=”HelloWorldHttpBinding” type=”ns:HelloWorldPortType”>

<http:binding verb=”POST”/>

<wsdl:operation name=”getHello”>

<http:operation location=”getHello”/>

<wsdl:input>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:input>

<wsdl:output>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getHelloWorld”>

<http:operation location=”getHelloWorld”/>

<wsdl:input>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:input>

<wsdl:output>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name=”getWorld”>

<http:operation location=”getWorld”/>

<wsdl:input>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:input>

<wsdl:output>

<mime:content type=”application/xml” part=”parameters”/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name=”HelloWorld”>

<wsdl:port name=”HelloWorldHttpSoap11Endpoint” binding=”ns:HelloWorldSoap11Binding”>

<soap:address location=”http://zgc-20150226yxm:8080/sayHello2Axis/services/HelloWorld.HelloWorldHttpSoap11Endpoint/”/>

</wsdl:port>

<wsdl:port name=”HelloWorldHttpSoap12Endpoint” binding=”ns:HelloWorldSoap12Binding”>

<soap12:address location=”http://zgc-20150226yxm:8080/sayHello2Axis/services/HelloWorld.HelloWorldHttpSoap12Endpoint/”/>

</wsdl:port>

<wsdl:port name=”HelloWorldHttpEndpoint” binding=”ns:HelloWorldHttpBinding”>

<http:address location=”http://zgc-20150226yxm:8080/sayHello2Axis/services/HelloWorld.HelloWorldHttpEndpoint/”/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-05/143334.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计7816字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7993666
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

  300 元就能买到的 ” 小钢炮 ”?惠普 7L 四盘位小主机解析 最近...
免费无广告!这款跨平台AI RSS阅读器,拯救你的信息焦虑

免费无广告!这款跨平台AI RSS阅读器,拯救你的信息焦虑

  免费无广告!这款跨平台 AI RSS 阅读器,拯救你的信息焦虑 在算法推荐主导信息流的时代,我们...
如何安装2026年最强个人助理ClawdBot、完整安装教程

如何安装2026年最强个人助理ClawdBot、完整安装教程

如何安装 2026 年最强个人助理 ClawdBot、完整安装教程 一、前言 学不完,根本学不完!近期,一款名...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
【1024程序员】我劝你赶紧去免费领一个AWS、华为云等的主机

【1024程序员】我劝你赶紧去免费领一个AWS、华为云等的主机

【1024 程序员】我劝你赶紧去免费领一个 AWS、华为云等的主机 每年 10 月 24 日,程序员们都会迎来...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
每天一个好玩的网站-手机博物馆-CHAZ 3D Experience

每天一个好玩的网站-手机博物馆-CHAZ 3D Experience

每天一个好玩的网站 - 手机博物馆 -CHAZ 3D Experience 一句话介绍:一个用 3D 方式重温...
国产开源公众号AI知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率

国产开源公众号AI知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率

国产开源公众号 AI 知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率 大家好,我是星哥,...
星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定! 前言 作为 NAS 玩家,你是否总被这些...
支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare 也瘫了连监控都挂,根因藏在哪? 最近两天的互联网堪称“故障...
小白也能看懂:什么是云服务器?腾讯云 vs 阿里云对比

小白也能看懂:什么是云服务器?腾讯云 vs 阿里云对比

小白也能看懂:什么是云服务器?腾讯云 vs 阿里云对比 星哥玩云,带你从小白到上云高手。今天咱们就来聊聊——什...