Grails CXF Web服务,包括WSDL中的所有方法

时间:2012-06-20 19:09:19

标签: web-services grails cxf

我尝试使用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版本的插件。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

只有使用“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;
}