WebService调用的奇怪问题
要做一个获取天气信息的东西,同事给了一个站点:
http://webservice.webxml.com.cn/webservices/weatherws.asmx?wsdl
用WSDL Importer自动生成了下面的两个文件:
第一个weatherws.cpp文件
#include <vcl.h>#pragma hdrstop#if !defined(weatherwsH)#include "weatherws.h"#endifnamespace NS_weatherws {_di_WeatherWSSoap GetWeatherWSSoap(bool useWSDL, AnsiString addr){ static const char* defWSDL= "http://webservice.webxml.com.cn/webservices/weatherws.asmx?wsdl"; static const char* defURL = "http://webservice.webxml.com.cn/webservices/weatherws.asmx"; static const char* defSvc = "WeatherWS"; static const char* defPrt = "WeatherWSSoap"; if (addr=="") addr = useWSDL ? defWSDL : defURL; THTTPRIO* rio = new THTTPRIO(0); if (useWSDL) { rio->WSDLLocation = addr; rio->Service = defSvc; rio->Port = defPrt; } else { rio->URL = addr; } _di_WeatherWSSoap service; rio->QueryInterface(service); if (!service) delete rio; return service;}static void RegTypes(){ /* WeatherWSSoap */ InvRegistry()->RegisterInterface(__interfaceTypeinfo(WeatherWSSoap), L"http://WebXml.com.cn/", L"utf-8"); InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(WeatherWSSoap), L"http://WebXml.com.cn/%operationName%"); /* getRegionDatasetResult */ RemClassRegistry()->RegisterXSClass(__classid(getRegionDatasetResult), L"http://WebXml.com.cn/", L"getRegionDatasetResult"); RemClassRegistry()->RegisterXSInfo(__arrayTypeinfo(ArrayOfString), L"http://WebXml.com.cn/", L"ArrayOfString"); /* getSupportCityDatasetResult */ RemClassRegistry()->RegisterXSClass(__classid(getSupportCityDatasetResult), L"http://WebXml.com.cn/", L"getSupportCityDatasetResult");}#pragma startup RegTypes 32}; // NS_weatherws
#ifndef weatherwsH#define weatherwsH#include <System.hpp>#include <InvokeRegistry.hpp>#include <XSBuiltIns.hpp>#include <SoapHTTPClient.hpp>namespace NS_weatherws {// ************************************************************************ //// The following types, referred to in the WSDL document are not being represented// in this file. They are either aliases[@] of other types represented or were referred// to but never[!] declared in the document. The types from the latter category// typically map to predefined/known XML or Borland types; however, they could also // indicate incorrect WSDL documents that failed to declare or import a schema type.// ************************************************************************ //// !:string - "http://WebXml.com.cn/"// !:string - "http://www.w3.org/2001/XMLSchema"class getRegionDatasetResult;class getSupportCityDatasetResult;// ************************************************************************ //// Namespace : http://WebXml.com.cn/// ************************************************************************ //class getRegionDatasetResult : public TRemotable {private: AnsiString Fs_schema;public:__published: __property AnsiString s_schema = { read=Fs_schema, write=Fs_schema };};typedef DynamicArray<AnsiString> ArrayOfString; /* "http://WebXml.com.cn/" */// ************************************************************************ //// Namespace : http://WebXml.com.cn/// ************************************************************************ //class getSupportCityDatasetResult : public TRemotable {private: AnsiString Fs_schema;public:__published: __property AnsiString s_schema = { read=Fs_schema, write=Fs_schema };};// ************************************************************************ //// Namespace : http://WebXml.com.cn/// soapAction: http://WebXml.com.cn/%operationName%// transport : http://schemas.xmlsoap.org/soap/http// binding : WeatherWSSoap// service : WeatherWS// port : WeatherWSSoap// URL : http://webservice.webxml.com.cn/webservices/weatherws.asmx// ************************************************************************ //__interface INTERFACE_UUID("{54393593-AC04-4DAB-BBF6-AB948B692BED}") WeatherWSSoap : public IInvokable{public: virtual getRegionDatasetResult* getRegionDataset() = 0; virtual ArrayOfString getRegionProvince() = 0; virtual ArrayOfString getRegionCountry() = 0; virtual getSupportCityDatasetResult* getSupportCityDataset(const AnsiString theRegionCode) = 0; virtual ArrayOfString getSupportCityString(const AnsiString theRegionCode) = 0; virtual ArrayOfString getWeather(const AnsiString theCityCode, const AnsiString theUserID) = 0; };typedef DelphiInterface<WeatherWSSoap> _di_WeatherWSSoap;_di_WeatherWSSoap GetWeatherWSSoap(bool useWSDL=false, AnsiString addr="");#endif // __weatherws_h__}; // NS_weatherws#if !defined(NO_IMPLICIT_NAMESPACE_USE)using namespace NS_weatherws;#endif
void __fastcall TForm1::Button1Click(TObject *Sender){ _di_WeatherWSSoap test; test = GetWeatherWSSoap(true,"http://webservice.webxml.com.cn/webservices/weatherws.asmx?wsdl"); TStringDynArray text = [color=#FF0000]test->getRegionProvince()[/color]; Memo1->Lines->Clear(); for(int i=0;i<text.get_length();i++) { Memo1->Lines->Add(text[i]); } }