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

一、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']
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值