0

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

4

1 回答 1

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;
}
于 2012-06-21T08:50:33.700 回答