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 リクエストで予期されるパラメータを確認しましたが、問題の原因となっている 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

あなたのスニペットでは、コンマを 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 に答える