web-services - Grails wslite SOAP参数导致解码错误

标签 web-services grails soap

我正在尝试将wslite(0.7.2.0)与Grails(2.4.4)结合使用以使用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
    }
}

异常(exception):
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>

最佳答案

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

这是一个可以从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()

关于web-services - Grails wslite SOAP参数导致解码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29402668/

相关文章:

c++ - 在 c++ WWSAPI Web 服务中处理 WS-Security PasswordDigest 模式

linux - 适用于 Linux 上 REST 和/或 SOAP Web 服务开发的堆栈/框架

web-services - 多个请求的服务持久化

grails - Grails maxSize约束不会使texbox变大

Tomcat 无法启动应用程序并超时——日志中的最后一行只是单词 "bad"

maven - Grails应用程序仅使用Maven运行,放弃对Grails的支持

java - 如何将字符串(XML)转换为 SOAP 消息

web-services - 如何在 jmeter 中为 SOAP 请求添加正确的签名

database - (Web) 服务依赖问题

web-services - 如何测试下面详述的 net.tcp 服务?