Delphi 客户端调用WebService

客户程序:

第一步:新建一个 Application。

第二步:File----->New----->Other------>WebServices----->WSDLimporter

第三步:

     生成了一个新的接口定义单元

    Wsdl Location中填入:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

然后确定即生成了一个新的接口定义单元

第四步:

在主form上放上一个按钮和一个Httprio组件(在WebServices页上),并引用第二个单元(即通过Soap Services Importer自动生成的单元)

第五步:

  在Httprio的属性页上的WsdlLocation里面填 上http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl;

  然后在Httprio属性页上的Port和Service上选择上相应的数据 即可。

第六步:客户调用程序

procedure TForm1.Button3Click(Sender: TObject);
var
  i: Integer;
  aryWeatherData: ArrayOfString2;
begin

  Memo1.Lines.Clear;

  aryWeatherData := (HTTPRIO1 as WeatherWSSoap).getWeather(edit1.Text,'');     //石家庄
  for i := 0 to high(aryWeatherData) do
  begin
    Memo1.Lines.Add(aryWeatherData[i]);
  end;

end;

 


 

 

 


参考:

  WeatherWebService
  接口文档说明: http://ws.webxml.com.cn/WebServices/WeatherWebService.asmx
  查询本天气预报Web Services支持的国内外城市或地区信息,

  提供一些 WebService 的网站:   http://www.webxml.com.cn/zh_cn/index.aspx

 

posted @ 2022-10-20 16:49  麦麦提敏  阅读(813)  评论(0编辑  收藏  举报