我用delphi7做下个测试应用,调用webservices ,代码如下: 
unit main; interface uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient,PublicInterface2; type 
  TForm1 = class(TForm) 
    Memo2: TMemo; 
    Memo1: TMemo; 
    HTTPRIO1: THTTPRIO; 
    Edit1: TEdit; 
    Button1: TButton; 
    Edit2: TEdit; 
    Label2: TLabel; 
  procedure Button1Click(Sender: TObject); 
      private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; ////以下是按钮下的代码 
procedure TForm1.Button1Click(Sender: TObject); 
Var 
  p : PublicInterface  ; 
begin 
    try 
  webser := edit1.Text; 
  HTTPRIO1.WSDLLocation := webser; 
  ininfo := memo2.Text; 
  p := HTTPRIO1 As PublicInterface ; 
    outinfo:= p.outCalculate(ininfo); 
  p:=nil; 
  memo1.Text := outinfo; 
    except 
  showmessage('webservice 地址可能不正确!或者服务就没有启动!'); 
end; 
end; 
这上边是一个按钮下的代码。测试正常。 
现在要用delphi 做一个 DLL。 不用 窗口了,也就是没有 Form 了,该怎么弄,我该怎么创建 HTTPRIO1 这个对象,代码该怎么写,写在哪里。这两天刚学 delphi 大家指点一下。

解决方案 »

  1.   

    注意2点:
    1.先在主调申请变量空间,把地址传给dll,dll调用webservice后,把值添入
    2.在dll内创建及使用httprio,也就是说,千万不要在主调中创建httprio,而后把地址传给dll,这样在HTTPRIO1 As PublicInterface 时肯定会出错,因为dll与主调的RTTI是不一样的
      

  2.   

    library Project1;uses
      SysUtils,
      InvokeRegistry, Rio, SOAPHTTPClient,PublicInterface2,
      Classes;{$R *.res}function wsCal(Url:PChar):PChar;
    var http:THTTPRIO;
        p : PublicInterface  ; 
    begin
      http:=THTTPRIO.Create(nil);
      http.WSDLLocation:=Url;
      p := HTTPRIO1 As PublicInterface ; 
        outinfo:= p.outCalculate(ininfo); 
      p:=nil; 
      result:=outinfo;
    end;exports
      wsCal;begin
    end.
    大概这样子吧,也不知道对不对,你放IDE里自己调试下
      

  3.   

    谢谢鹏哥!但编译时过不去。如下提示:
    [Error] jmybinterface.dpr(112): Undeclared identifier: 'HTTPRIO1'