Grails wslite SOAP params导致Unmarshalling错误

时间:2015-04-01 23:32:48

标签: web-services grails soap

我正在尝试使用带有Grails(2.4.4)的wslite(0.7.2.0)来使用SOAP Web服务。我能够让这个例子起作用:

withSoap(serviceURL: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx') {
    def response = send(SOAPAction: 'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
        body {
            GetMothersDay(xmlns: 'http://www.27seconds.com/Holidays/US/Dates/') {
                year(2011)
            }
        }
    }

    println response.GetMothersDayResponse.GetMothersDayResult.text()
}

但是每当我尝试命中另一个需要参数的端点时,我都会得到一个Unmarshall异常。

我的代码:

withSoap(serviceURL: 'http://www.wcc.nrcs.usda.gov/awdbWebService/services?wsdl') {
    def response = send {
        body {
            getStations("xmlns": 'http://www.wcc.nrcs.usda.gov/ns/awdbWebService') {
                stateCds(Arrays.asList("OR"))
                logicalAnd(true)
            }
        }
    }

    response.getStationsResponse.return.each{resp->
        println resp
    }
}

例外:

Message
    soap:Client - Unmarshalling Error: unexpected element (uri:"http://www.wcc.nrcs.usda.gov/ns/awdbWebService", local:"stateCds").
    Expected elements are <{}elementCds>,<{}maxElevation>,<{}networkCds>,<{}heightDepths>,<{}ordinals>,<{}maxLongitude>,
    <{}minElevation>,<{}hucs>,<{}stateCds>,<{}minLatitude>,<{}countyNames>,<{}maxLatitude>,<{}minLongitude>,<{}stationIds>,<{}logicalAnd>

2 个答案:

答案 0 :(得分:0)

切换到groovy-wslite-1.1.0思考可能插件就是问题。不幸的是,尝试传递参数时会抛出相同的Unmarshalling异常。通过将原始XML传递给服务,我能够获得使用参数的请求。

答案 1 :(得分:0)

问题是stateCdslogicalAnd元素不应该是命名空间。您应用于getStations元素的命名空间将由这些子元素继承。

以下是可以从Groovy控制台运行的工作示例:

@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
import wslite.soap.*

def client = new SOAPClient('http://www.wcc.nrcs.usda.gov/awdbWebService/services')
def response = client.send {
    body {
        'awdb:getStations'("xmlns:awdb": 'http://www.wcc.nrcs.usda.gov/ns/awdbWebService') {
            stateCds('OR')
            logicalAnd(true)
        }
    }
}

assert !response.getStationsResponse.isEmpty()