1. 程式人生 > >Delphi 呼叫webservice介面的三類方法

Delphi 呼叫webservice介面的三類方法

一、使用嚮導

     1.匯入wsdl檔案:file--new----other----webservice---WSDLimporter---輸入wsdl地址

        http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

        

        完成之後,即可匯入wsdl檔案。

        注:結尾處的'?wsdl'不能少。

      2.在匯入的wsdl檔案中手動新增部分註冊程式碼

  InvRegistry.RegisterInterface(TypeInfo(qqOnlineWebServiceSoap), 'http://WebXml.com.cn/', 'utf-8');
  InvRegistry.RegisterInvokeOptions(TypeInfo(qqOnlineWebServiceSoap),ioDocument);
//此處必須手動新增,delphi無法自動生成 InvRegistry.RegisterDefaultSOAPAction(TypeInfo(qqOnlineWebServiceSoap), 'http://WebXml.com.cn/qqCheckOnline');

      3.呼叫程式碼

複製程式碼
var
  statusQuery:qqOnlineWebServiceSoap;
  qqNumber:string;
  statusStr:string;
begin
  statusQuery:
=GetqqOnlineWebServiceSoap; qqNumber:='516220662'; statusStr:=statusQuery.qqCheckOnline(qqNumber); ShowMessage(statusStr); end;
複製程式碼

      4.執行結果:

       

      PS:直接瀏覽器訪問

      a) http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx

          

       b)輸入QQ號進行測試:

          

       c)呼叫結果:

          

二、使用HTTPRIO控制元件

       1.在介面上拖放一個HTTPRIO控制元件

           

       2.設定url屬性

          http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

       3.呼叫程式碼

複製程式碼
var
  statusStr:string;
begin
   statusStr:=(HTTPRIO1 as qqOnlineWebServiceSoap).qqCheckOnline('516220662');
   ShowMessage(statusStr);
end;
複製程式碼

       4.執行結果

         


轉摘自:http://www.cnblogs.com/edisonfeng/archive/2012/08/17/2644452.html