一:webService基于webapp,首先创建webapp名称test_webservice.在webcontent目录下面创建deploy.wsdd文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="HelloServices" provider="java:RPC">
<parameter name="className" value="com.webservice.HelloService"/>
<parameter name="allowedMethods" value="*"/>
</service>
</deployment>
HelloServices为webservice的名称 provider为webservice的类型 com.webservice.HelloService为要发布为webservice的类。
value="*"表示对外暴露所有的方法。
编写两个类。一个HelloService,一个testWebService.
完成之后开始发布:
第一步:在web.xml中配置axis.
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
访问http://localhost:8083/test_webservice/services
And now... Some Services
在webcontent目录下面写一个批处理文件*.bat:java -Djava.ext.dirs=%lib% org.apache.axis.client.AdminClient -lhttp://192.168.1.113:8083/test_webservice/AxisServlet deploy.wsdd
或者直接在命令行窗口执行返回结果:
D:\john\new\workspace\test_webservice\WebContent>java -Djava.ext.dirs=%lib% org.
apache.axis.client.AdminClient -lhttp://192.168.1.113:8083/test_webservice/AxisS
ervlet deploy.wsdd
Processing file deploy.wsdd
<Admin>Done processing</Admin>
表示将java类发布webservice成功。
访问http://localhost:8083/test_webservice/services
And now... Some Services
- HelloServices (wsdl)
- sayHelloToPerson
- sayHello
- AdminService (wsdl)
- AdminService
- Version (wsdl)
- getVersion
访问http://localhost:8083/test_webservice/HelloService?wsdl生成如下:
<wsdl:definitions targetNamespace="http://localhost:8083/test_webservice/HelloServices"><!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
--><wsdl:message name="sayHelloToPersonResponse"><wsdl:part name="sayHelloToPersonReturn" type="xsd:string"/></wsdl:message><wsdl:message name="sayHelloRequest">
</wsdl:message><wsdl:message name="sayHelloToPersonRequest"><wsdl:part name="name" type="xsd:string"/></wsdl:message><wsdl:message name="sayHelloResponse"><wsdl:part name="sayHelloReturn" type="xsd:string"/></wsdl:message><wsdl:portType name="HelloService"><wsdl:operation name="sayHelloToPerson" parameterOrder="name"><wsdl:input message="impl:sayHelloToPersonRequest" name="sayHelloToPersonRequest"/><wsdl:output message="impl:sayHelloToPersonResponse" name="sayHelloToPersonResponse"/></wsdl:operation><wsdl:operation name="sayHello"><wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest"/><wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse"/></wsdl:operation></wsdl:portType><wsdl:binding name="HelloServicesSoapBinding" type="impl:HelloService"><wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="sayHelloToPerson"><wsdlsoap:operation soapAction=""/><wsdl:input name="sayHelloToPersonRequest"><wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.com" use="encoded"/></wsdl:input><wsdl:output name="sayHelloToPersonResponse"><wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8083/test_webservice/HelloServices" use="encoded"/></wsdl:output></wsdl:operation><wsdl:operation name="sayHello"><wsdlsoap:operation soapAction=""/><wsdl:input name="sayHelloRequest"><wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservice.com" use="encoded"/></wsdl:input><wsdl:output name="sayHelloResponse"><wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8083/test_webservice/HelloServices" use="encoded"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="HelloServiceService"><wsdl:port binding="impl:HelloServicesSoapBinding" name="HelloServices"><wsdlsoap:address location="http://localhost:8083/test_webservice/HelloServices"/></wsdl:port></wsdl:service></wsdl:definitions>
就表明一个webservice发布成功了