Windows Server 2008 R2 64 位 IIS 7.5 Delphi XE2
我使用 delphi XE2 制作了一个简单的 WebService/ISAPI DLL。这个 Web 服务有一个函数,它返回两个数字之和,并制作了一个简单的客户端应用程序来测试这个函数。当我将它(与客户端一起)编译为 32 位应用程序(在具有 32 位启用的应用程序池的虚拟目录中)时,一切正常
当我将它编译为 64 位 DLL(客户端也被编译为 64 位应用程序)时,我总是收到访问冲突错误“类 ERemotableException 并带有消息‘在模块‘MyWebService.dll’中的地址 0000000002199F33 的访问冲突’。阅读地址 0000000000000000'。”
我检查了我应该做的所有 IIS7.5 权限(32 位 ISAPI DLL 工作正常)并且问题一直出现。
这是一些快速的测试反馈:
如果我使用 TRemotable 类后代在过程中传递数据 --> 没有 pb
但是,编写一个返回整数的简单函数会导致访问冲突。我还尝试使用本机 wndows 数据类型,例如 Int64,但没有运气。
以前有人遇到过这样的问题吗?因为坦率地说我很绝望。
这是代码:
这是webmodule接口
{ 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.
和实施
{ 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.
这是客户端应用程序 WSDl pascal 文件:
// ************************************************************************ //
// 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.
以及调用该函数的测试单元
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.