Delphi XE2 64 bit ISAPI Access Violation

人走茶凉 提交于 2019-12-13 21:52:23

问题


Windows Server 2008 R2 64 bit IIS 7.5 Delphi XE2

i made a simple WebService/ISAPI DLL using delphi XE2. this web service has a function that returns the sum of two numbers and made a simple client application to test this function. When i compile it (along with the client) as a 32 bit application (in a virtual directory with a 32-bit enabled app pool), all works fine

when i compile it as a 64 bit DLL (the client is also compiled as a 64-bit aplication) i alws get an access violation error "class ERemotableException with message 'Access violation at address 0000000002199F33 in module 'MyWebService.dll'. Read of address 0000000000000000'."

i checked all IIS7.5 permissions i should do (the 32 bit ISAPI DLL works fine) and the problem kept appearing.

here is some quick test feed back:

if i used a TRemotable class descendant to pass data in a procedure --> no pb

however, writing a simple function that returns an integer causes the access violation. i also tried to use native wndows data types such as Int64 without luck.

did some one had such a problem before? because frankly i am desperate.

Here is the code:

This is the webmodule interface

{ Invokable interface IMyDebugModule }

unit MyDebugModuleIntf;

interface

uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns;

type

  { Invokable interfaces must derive from IInvokable }
  IMyDebugModule = interface(IInvokable)
  ['{02A5AD69-24E4-447B-8882-804DA687A0F2}']

    { Methods of Invokable interface must not use the default }
    { calling convention; stdcall is recommended }
    //function MyFunc():double;stdcall;
    function MyFunc():Int64;stdcall;
  end;

implementation

initialization
  { Invokable interfaces must be registered }
  InvRegistry.RegisterInterface(TypeInfo(IMyDebugModule));

end.

and the implementaion

{ Invokable implementation File for TMyDebugModule which implements IMyDebugModule }

unit MyDebugModuleImpl;

interface

uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, MyDebugModuleIntf;

type

  { TMyDebugModule }
  TMyDebugModule = class(TInvokableClass, IMyDebugModule)
  public
    function MyFunc():Int64;stdcall;
  end;

implementation




{ TMyDebugModule }

function TMyDebugModule.MyFunc: Int64;
begin
  Result := 101;
end;

{ TMyDebugModule }


initialization
{ Invokable classes must be registered }
   InvRegistry.RegisterInvokableClass(TMyDebugModule);
end.

and here is the client app WSDl pascal file:

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : C:\MyWorkingDir64\MyTests\WebServiceDebug\Client\IMyDebugModuleWSDL.xml
// Version  : 1.0
// (19/04/2013 09:46:52 - - $Rev: 37707 $)
// ************************************************************************ //

unit IMyDebugModuleWSDL;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type

  // ************************************************************************ //
  // 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 Embarcadero types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:long            - "http://www.w3.org/2001/XMLSchema"[]


  // ************************************************************************ //
  // Namespace : urn:MyDebugModuleIntf-IMyDebugModule
  // soapAction: urn:MyDebugModuleIntf-IMyDebugModule#MyFunc
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // use       : encoded
  // binding   : IMyDebugModulebinding
  // service   : IMyDebugModuleservice
  // port      : IMyDebugModulePort
  // URL       : http://devserver2008/BahaaDebug/BahaaDebug.dll/soap/IMyDebugModule
  // ************************************************************************ //
  IMyDebugModule = interface(IInvokable)
  ['{64033E30-8D6E-F252-4E38-55502BF4E1A5}']
    function  MyFunc: Int64; stdcall;
  end;

function GetIMyDebugModule(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): IMyDebugModule;


implementation
  uses SysUtils;

function GetIMyDebugModule(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IMyDebugModule;
const
  defWSDL = 'C:\MyWorkingDir64\MyTests\WebServiceDebug\Client\IMyDebugModuleWSDL.xml';
  defURL  = 'http://devserver2008/BahaaDebug/BahaaDebug.dll/soap/IMyDebugModule';
  defSvc  = 'IMyDebugModuleservice';
  defPrt  = 'IMyDebugModulePort';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as IMyDebugModule);
    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;
end;


initialization
  { IMyDebugModule }
  InvRegistry.RegisterInterface(TypeInfo(IMyDebugModule), 'urn:MyDebugModuleIntf-IMyDebugModule', '');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IMyDebugModule), 'urn:MyDebugModuleIntf-IMyDebugModule#MyFunc');

end.

and the test unit that called the function

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IMyDebugModuleWSDL, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  w:IMyDebugModule;
  i:integer;
begin
  w := GetIMyDebugModule(True,'',nil);
  i := w.MyFunc;
  caption := IntToStr(i);
end;

end.

来源:https://stackoverflow.com/questions/16083434/delphi-xe2-64-bit-isapi-access-violation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!