加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

我的webservice Hello world-axis

发布时间:2020-12-16 23:04:49 所属栏目:安全 来源:网络整理
导读:准备: 不论是服务端还是客户端,都要导入相关包,报名如下: activation.jar axis-ant.jar axis.jar commons-discovery-0.2.jar commons-logging-1.0.4.jar jaxrpc.jar log4j-1.2.8.jar mail.jar saaj.jar wsdl4j-1.5.1.jar 服务端: 写一个类,如下: ? Ja

准备:

不论是服务端还是客户端,都要导入相关包,报名如下:

activation.jar

axis-ant.jar

axis.jar

commons-discovery-0.2.jar

commons-logging-1.0.4.jar

jaxrpc.jar

log4j-1.2.8.jar

mail.jar

saaj.jar

wsdl4j-1.5.1.jar

服务端:

写一个类,如下:

?

Java代码??

收藏代码

  1. package?server;??
  2. ??
  3. public?class?Hello?{??
  4. ????public?String?sayHello(String?name)?{??
  5. ????????return?name?+?"tHello!";??
  6. ????}??
  7. }??

?在web.xml文件中加入以下配置:

Xml代码??

收藏代码

    <servlet>??
  1. ????servlet-name>InterfaceService</servlet-class>org.apache.axis.transport.http.AxisServletload-on-startup>7servlet-mappingurl-pattern>/services/*>??

?为以上的类配置,建立一个文件deploy.wsdd,加入以下内容:

deployment?xmlns="http://xml.apache.org/axis/wsdd/"??
  • ????xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"service?name="Hello"?provider="java:RPC" ????????parameter?name="className"?value="server.Hello"?/>??
  • parameter?name="allowedMethods"?value="*"?servicedeployment ?新建文件deploy.bat,内容如下:

    Bat代码??

    收藏代码

      set?Axis_Lib=E:apache-tomcat-6.0.26webappsaxisServerWEB-INFlib??
    1. set?Java_Cmd=java?-Djava.ext.dirs=%Axis_Lib%??
    2. set?Axis_Servlet=http://localhost:8888/axisServer/services/InterfaceService??
    3. %Java_Cmd%?org.apache.axis.client.AdminClient?-l%Axis_Servlet%?deploy.wsdd??

    ?在deploy.bat文件所在的目录,用命令提示符运行该文件,运行成功后打开地址:http://localhost:8888/axisServer/services/Hello?wsdl。此时服务端已经完成,将网页内容复制下来。

    客户端:

    将复制下来的内容放在客户端根目录的wsdl文件夹下的axisServer.xml文件上:

    ??<?xml?version="1.0"?encoding="UTF-8"??>???
  • -?wsdl:definitions?targetNamespace="http://localhost:8888/axisServer/services/Hello"?xmlns:apachesoap="http://xml.apache.org/xml-soap"?xmlns:impl="http://localhost:8888/axisServer/services/Hello"?xmlns:intf="http://localhost:8888/axisServer/services/Hello"?xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"?xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"?xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"?xmlns:xsd="http://www.w3.org/2001/XMLSchema" -?<!--???
  • WSDL?created?by?Apache?Axis?version:?1.4??
  • Built?on?Apr?22,?2006?(06:55:48?PDT)??
  • ??-->???
  • wsdl:message?name="sayHelloResponse"wsdl:part?name="sayHelloReturn"?type="xsd:string"?/>???
  • wsdl:messagewsdl:message?name="sayHelloRequest"wsdl:part?name="name"?type="xsd:string"?wsdl:portType?name="Hello"wsdl:operation?name="sayHello"?parameterOrder="name"wsdl:input?message="impl:sayHelloRequest"?name="sayHelloRequest"?wsdl:output?message="impl:sayHelloResponse"?name="sayHelloResponse"?wsdl:operationwsdl:portTypewsdl:binding?name="HelloSoapBinding"?type="impl:Hello"wsdlsoap:binding?style="rpc"?transport="http://schemas.xmlsoap.org/soap/http"?wsdl:operation?name="sayHello"wsdlsoap:operation?soapAction=""?wsdl:input?name="sayHelloRequest"wsdlsoap:body?encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"?namespace="http://server"?use="encoded"?wsdl:inputwsdl:output?name="sayHelloResponse"wsdlsoap:body?encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"?namespace="http://localhost:8888/axisServer/services/Hello"?use="encoded"?wsdl:outputwsdl:bindingwsdl:service?name="HelloService"wsdl:port?binding="impl:HelloSoapBinding"?name="Hello"wsdlsoap:address?location="http://localhost:8888/axisServer/services/Hello"?wsdl:portwsdl:servicewsdl:definitions ?在同等目录下建立WSDL2Java.bat,内容如下:

    set?Axis_Lib=E:workspaceaxisServerClientWebRootWEB-INFlib??
  • set?Output_Path=E:workspaceaxisServerClientsrc??
  • set?Package=server??
  • %Java_Cmd%?org.apache.axis.wsdl.WSDL2Java?-o%Output_Path%?-p%Package%?axisServer.wsdl??
  • ?在该文件所在目录下用命令提示符运行,运行完毕后,在src目录下,会多出一堆文件。建立测试文件测试:

    package?test;??
  • import?java.rmi.RemoteException;??
  • import?javax.xml.rpc.ServiceException;??
  • import?server.HelloService;??
  • import?server.HelloServiceLocator;??
  • class?WeatherClient?{??
  • static?void?main(String[]?args)?{??
  • ????????HelloService?service?=?new?HelloServiceLocator();??
  • ????????String?info?=?null;??
  • try?{??
  • ????????????info?=?service.getHello().sayHello("July");??
  • ????????}?catch?(ServiceException?e)?{??
  • ????????????e.printStackTrace();??
  • catch?(RemoteException?e)?{??
  • ????????}??
  • ????????System.out.println(info);??
  • }?????
  • ?运行后会打印:July?? ?Hello!

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读