2

我正在尝试使用 Google App 脚本调用 WebserviceX 提供的 GetWeather 肥皂服务,并在运行脚本时收到以下错误:

Request failed for http://www.webservicex.net/globalweather.asmx returned code 500. Server response: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Data.SqlClient.SqlException: Procedure or function 'getWeather' expects parameter '@CountryName', which was not supplied. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at WebServicex.GlobalWeather.GetWeather(String CityName, String CountryName) --- End of inner exception stack trace ---</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> (line 12)

我已经检查了 GetWeather SOAP 服务的 SOAP 请求中预期的参数,但我无法了解导致问题的肥皂请求中的哪个元素。以下是相同的脚本代码:

function testSoapSerivce() {
var wsdl2 = SoapService.wsdl("http://www.webservicex.net/globalweather.asmx?WSDL");
  Logger.log(wsdl2.getServiceNames());
  var weatherService=wsdl2.getService("GlobalWeather");
    var param2 = [ "GetWeather",
                { "xmlns" : "http://www.webservicex.net/" },
                [ "CityName", "New Delhi" ],
                [ "CountryName", "India"],  
              ];
  var envelope2 = weatherService.getSoapEnvelope("GetWeather", param2)
  Logger.log(envelope2);
  var result2 = weatherService.GetWeather(param2);
 Logger.log(result2.toXmlString());
}

GetWeather 服务详情可在以下链接中找到:

http://www.webservicex.net/ws/WSDetails.aspx?CATID=12&WSID=56

4

1 回答 1

1

在您的代码段中,您似乎添加了一个逗号到多个逗号。不用最后一个试试 最后一个"India"],];在数组中定义了一个空索引。

我已经查看了 webservicex 站点。实际上有一种更简单的方法来获取数据。该站点还提供 HTTP GET 服务

HTTP GET

The following is a sample HTTP GET request and response. The placeholders shown need to be replaced with actual values.

GET /globalweather.asmx/GetWeather?CityName=string&CountryName=string HTTP/1.1
Host: www.webservicex.net
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">string</string>

为什么不使用 UrlFetch 服务?

于 2012-09-09T18:34:11.497 回答