【问题标题】:Grails CXF web service including all methods in WSDLGrails CXF Web 服务,包括 WSDL 中的所有方法
【发布时间】:2012-06-21 16:50:33
【问题描述】:

我正在尝试使用 CXF 插件在 Grails 中实现 SOAP Web 服务。我的服务类很简单。

package com.ld.api

import com.ld.domain.*
import javax.jws.*
import grails.converters.XML


class CabinetService {


    static transactional = true
    static expose=['cxf']
    String getCabinetList() {

        String list = Cabinet.list()

        //return list as XML

        return "jim"

    }


    def serviceMethod() {
        println "IN serviceMethod"
        "Hello...."
    }


}

我得到了这个 WSDL:

<wsdl:definitions name="CabinetService" targetNamespace="http://api.ld.com/"><wsdl:types><xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://api.ld.com/"><xsd:element name="serviceMethod" type="tns:serviceMethod"/><xsd:complexType name="serviceMethod"><xsd:sequence/></xsd:complexType><xsd:element name="serviceMethodResponse" type="tns:serviceMethodResponse"/><xsd:complexType name="serviceMethodResponse"><xsd:sequence><xsd:element minOccurs="0" name="return" type="xsd:anyType"/></xsd:sequence></xsd:complexType></xsd:schema></wsdl:types><wsdl:message name="serviceMethodResponse"><wsdl:part element="tns:serviceMethodResponse" name="parameters">
    </wsdl:part></wsdl:message><wsdl:message name="serviceMethod"><wsdl:part element="tns:serviceMethod" name="parameters">
    </wsdl:part></wsdl:message><wsdl:portType name="CabinetServicePortType"><wsdl:operation name="serviceMethod"><wsdl:input message="tns:serviceMethod" name="serviceMethod">
    </wsdl:input><wsdl:output message="tns:serviceMethodResponse" name="serviceMethodResponse">
    </wsdl:output></wsdl:operation></wsdl:portType><wsdl:binding name="CabinetServiceSoapBinding" type="tns:CabinetServicePortType"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="serviceMethod"><soap:operation soapAction="" style="document"/><wsdl:input name="serviceMethod"><soap:body use="literal"/></wsdl:input><wsdl:output name="serviceMethodResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="CabinetService"><wsdl:port binding="tns:CabinetServiceSoapBinding" name="CabinetServicePort"><soap:address location="http://localhost:8080/LucanDOCS2013/services/cabinet"/></wsdl:port></wsdl:service></wsdl:definitions>

自动生成的“serviceMethod”包含在 WSDL 中,但不包含 getCabinetList()。我尝试了各种注释组合,但没有运气。

我正在使用 grails 2.0.3 和插件的 0.9.0 版本。任何帮助将不胜感激。

【问题讨论】:

    标签: web-services grails cxf


    【解决方案1】:

    只有用“def”定义的方法在 WSDL 中可见,getCabinetList() 会丢失它

    也可以使用:static expose = [ 'cxfjax' ] ... 查看最新的插件文档。

    我也在导出的方法中使用它:

    @WebMethod( operationName="createUpdateUser" )
    @WebResult( name="result" )
    def ResultDTO createUpdateUser( @WebParam( name="authorizationCode" ) String a uthorizationCode,
                                    @WebParam( name="username" ) String username ) ) { ... }
    

    另外不要忘记对类进行注释,您是通过服务传输的,或者您最终会得到没有参数和数据类型的 WSDL:

    @XmlAccessorType(XmlAccessType.FIELD)
    public class ResultDTO {
        int code;
        String message;
    }
    

    【讨论】:

    • 谢谢汤姆。我显然在使用旧插件的文档。您的建议非常有效。
    • 太好了,它有帮助,快乐的编码! :-)
    猜你喜欢
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 2011-03-28
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多