1.新建一个App, 放上一个button, listbox, HTTPRIO
2.新建webservices -> wsdlInmporter 导入你这个网站的Wsdl 让程序知道调用规则
不出意外会生成个WeatherWebService.pas ,主窗体引用它
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl3.设置HTTPRIO的 port, service, wsdlLocation 会下拉出来
4.写点代码吧
//得到支持的地区
procedure TForm1.Button1Click(Sender: TObject);
var
AOS,ss: ArrayOfString;
I: Integer;
begin
AOS := (HTTPRIO1 as WeatherWebServiceSoap).getSupportProvince;
for I := Low(AOS) to High(AOS) do
Listbox1.Items.Add(AOS[I]); -- 可以把所有省份列出来但是使用下面代码,出现错误:
-- 取省份下的城市
ss := (HTTPRIO1 as WeatherWebServiceSoap).getSupportCity('广西')
-- 取城市的天气
ss := (HTTPRIO1 as WeatherWebServiceSoap).getWeatherbyCityName('深圳');---- 错误信息为:
Project Project1.exe raised exception class ERemotableException with message '服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。'. Process stopped. Use Step or Run to continue.
2.新建webservices -> wsdlInmporter 导入你这个网站的Wsdl 让程序知道调用规则
不出意外会生成个WeatherWebService.pas ,主窗体引用它
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl3.设置HTTPRIO的 port, service, wsdlLocation 会下拉出来
4.写点代码吧
//得到支持的地区
procedure TForm1.Button1Click(Sender: TObject);
var
AOS,ss: ArrayOfString;
I: Integer;
begin
AOS := (HTTPRIO1 as WeatherWebServiceSoap).getSupportProvince;
for I := Low(AOS) to High(AOS) do
Listbox1.Items.Add(AOS[I]); -- 可以把所有省份列出来但是使用下面代码,出现错误:
-- 取省份下的城市
ss := (HTTPRIO1 as WeatherWebServiceSoap).getSupportCity('广西')
-- 取城市的天气
ss := (HTTPRIO1 as WeatherWebServiceSoap).getWeatherbyCityName('深圳');---- 错误信息为:
Project Project1.exe raised exception class ERemotableException with message '服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。'. Process stopped. Use Step or Run to continue.
for I := Low(AOS) to High(AOS) do
Listbox1.Items.Add(AOS[I]); -- 可以把所有省份列出来
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
RIO.HTTPWebNode.UseUTF8InHeader:= True; //这里加上这一句
try
Result := (RIO as TestStationSoap);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
InvRegistry.RegisterInterface(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WeatherWebServiceSoap), 'http://WebXml.com.cn/%operationName%');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://WebXml.com.cn/', 'ArrayOfString');
RemClassRegistry.RegisterXSClass(getSupportDataSetResult, 'http://WebXml.com.cn/', 'getSupportDataSetResult');
InvRegistry.RegisterInvokeOptions(TypeInfo(WeatherWebServiceSoap), ioDocument);//这里加上这一句
那就记得在前面加上这句
HTTPRIO1.HTTPWebNode.UseUTF8InHeader:= True;