0

I'm trying to learn how to use WSDL's to call web services from a Grails project. I've been provided with the WSDL and some XML results for reference.

I've been able to generate Java code from the WSDL, and everything seems to be working correctly.

Here's the WSDL: http://www.restfulwebservices.net/rest/USAZipCodeService.svc?wsdl

And here is the XML: http://api.geonames.org/postalCodeSearch?placename=MN&username=demo

I am receiving this exception in my project:

ERROR client.WebServiceClientFactoryImpl$WSClientInvocationHandler - No namespace on "geonames" element. javax.xml.ws.soap.SOAPFaultException: No namespace on "geonames" element.

It seems like it is saying that the XML returned isn't valid for SOAP? Am I missing/misunderstanding some pieces the puzzle here? It is all pretty new to me.

Edit: I am trying to use a Grails plugin called cxf client: https://github.com/ctoestreich/cxf-client

It is configured with the following in Config.groovy (something could be wrong/missing here?):

wsdl = "http://www.restfulwebservices.net/wcf/USAZipCodeService.svc?wsdl"
namespace = "cxf.client.postalcode"
clientInterface = "cxf.client.postalcode.IPostalCodeService" 
serviceEndpointAddress = "http://api.geonames.org/postalCodeSearch"
4

1 回答 1

1

我猜您只是将http://api.geonames.org/postalCodeSearch?placename=MN&username=demo作为参数返回的 XML 发送到 Web 服务。显然,从返回的 WSDL 描述中您可以看到没有名为geonames的元素,因此SOAPFaultException异常是一个相当公平的结果。

要修复它,您必须仔细参考WSDL描述,以确保调用方法具有正确的参数,可与 USAZipCodeService WSDL 描述标签中定义的任何内容(如<wsdl:operation>和)配合使用<wsdl:message>

另一个问题:在您的调用程序和 Config.groovy 中提到了 2 个不同的 WSDL。前者是 RESTful 服务,后者是 SOAP 服务。它们使用不同的调用方法和参数,因此请确保您的代码也具有一致的调用程序和参数。

于 2013-03-11T04:03:32.550 回答