2015-04-01 72 views
0

我正在尝试使用wslite(0.7.2.0)和Grails(2.4.4)来使用SOAP Web服务。我能得到的例子来工作:Grails wslite SOAP params导致Unmarshalling错误

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() 
} 

但每当我试着打需要参数另一个端点,我得到一个解组异常。

我的代码:

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> 
+0

当我看WSDL,我看到stateCds需要一个字符串参数。而不是Arrays.asList(“OR”),试试“OR”。 – Stealth 2015-04-02 13:41:56

+0

是的,我尝试使用stateCds(“OR”)具有相同的异常 – 2015-04-02 14:23:51

+0

尝试将您的soapAction设置为“”空字符串。如果我没有定义soapAction,那么过去我曾经有过这样的例子,它已经炸毁了。 – Stealth 2015-04-02 16:59:15

回答

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() 
+0

Namspacing the children was the problem。上面的答案按预期工作。谢谢! – 2015-04-03 11:23:27

0

切换到常规-wslite-1.1.0想也许这个插件是问题。不幸的是,当试图传递参数时抛出相同的解组异常。通过将原始XML传递给服务,我能够获得使用参数的请求。