grails框架中webService插件的使用(axis2,cxf)

来源:互联网 发布:jdbc 连接mysql 编辑:程序博客网 时间:2024/06/10 00:00

一、cxf插件的使用:

1、运行命令:

grails install-plugin cxf

2、 正确安装后在idea中可以看到如下图:



3、编写一个WebService的方法;新建一个Service类跟普通的没区别,建好后在服务类中加入:



 4、在浏览器访问http://localhost:8080/项目名/services/服务类名(符合grails服务类的写法)?wsdl,如:

http://localhost:8080/shopping/services/shop?wsdl

 5、如果正确的话会在浏览器中生成一个xml文件,比如我的:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="ShopService" targetNamespace="http://shopping/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://shopping/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  <wsdl:message name="add">    <wsdl:part element="tns:add" name="parameters">    </wsdl:part>  </wsdl:message>  <wsdl:message name="login">    <wsdl:part element="tns:login" name="parameters">    </wsdl:part>  </wsdl:message>  <wsdl:message name="loginResponse">    <wsdl:part element="tns:loginResponse" name="parameters">    </wsdl:part>  </wsdl:message>  <wsdl:message name="addResponse">    <wsdl:part element="tns:addResponse" name="parameters">    </wsdl:part>  </wsdl:message>  <wsdl:portType name="ShopServicePortType">    <wsdl:operation name="add">      <wsdl:input message="tns:add" name="add">    </wsdl:input>      <wsdl:output message="tns:addResponse" name="addResponse">    </wsdl:output>    </wsdl:operation>    <wsdl:operation name="login">      <wsdl:input message="tns:login" name="login">    </wsdl:input>      <wsdl:output message="tns:loginResponse" name="loginResponse">    </wsdl:output>    </wsdl:operation>  </wsdl:portType>  <wsdl:binding name="ShopServiceSoapBinding" type="tns:ShopServicePortType">    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>    <wsdl:operation name="add">      <soap:operation soapAction="" style="document"/>      <wsdl:input name="add">        <soap:body use="literal"/>      </wsdl:input>      <wsdl:output name="addResponse">        <soap:body use="literal"/>      </wsdl:output>    </wsdl:operation>    <wsdl:operation name="login">      <soap:operation soapAction="" style="document"/>      <wsdl:input name="login">        <soap:body use="literal"/>      </wsdl:input>      <wsdl:output name="loginResponse">        <soap:body use="literal"/>      </wsdl:output>    </wsdl:operation>  </wsdl:binding>  <wsdl:service name="ShopService">    <wsdl:port binding="tns:ShopServiceSoapBinding" name="ShopServicePort">      <soap:address location="http://localhost:8080/shopping/services/shop"/>    </wsdl:port>  </wsdl:service></wsdl:definitions>

 6、用eclipse生成客户端:

(1)新建WebServiceClient



 (2)输入地址,与浏览器的一致:



(3)生成客户端即可访问;

 

二、axis2插件的使用

1、axis2与cxf不同有两点:

(1)安装:

grails install-plugin axis2

(2)服务类使用:

 static expose=['axis2']
  • 大小: 11.4 KB
  • 大小: 19.1 KB
  • 大小: 9.7 KB
  • 大小: 57.3 KB
  • 查看图片附件
0 0