0

我有以下代码创建 RemObjects 服务的实例并调用 .net 服务器

class function TLabelPrintingServiceProxy.GetInstance: ILabelPrintingManager;
var
  LRoRemoteService: TRoRemoteService;
begin
  LRoRemoteService := TRoRemoteService.Create(nil);
  LRoRemoteService.Message := TROSOAPMessage.Create();
  LRoRemoteService.Channel := TROIndyHTTPChannel.Create(nil);
  LRoRemoteService.Channel.TargetUri := TROUri.Create(ILabelPrintingIntf.LabelPrintingManager_EndPointURI);

  Result := (LRoRemoteService as ILabelPrintingManager);
end;

对 .net 服务的调用是这样执行的:

  try
        Result := BinaryArray.Create;
        LLabelPrintingManager := TLabelPrintingServiceProxy.GetInstance();
        Result.Add(LLabelPrintingManager.GetVSSLabelImage(APrintJob));
    finally 
        TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingManager);
    end;

调用后,LLabelPrintingManager 接口应该由 RemObjects 自动释放,但它不会并泄漏使用的对象。

我已经尝试在 ReleaseLabelPrintingServiceProxyInstance (下面的代码)上手动释放服务实例中的所有对象,但它仍然在泄漏

class procedure TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(aILabelPrintingManagerIntf: ILabelPrintingManager);
var
  lProxy: TRoProxy;
begin
  lProxy := TROProxy(aILabelPrintingManagerIntf);
  TROIndyHTTPChannel(lProxy.__TransportChannel).TargetUri.Free;
//  TROIndyHTTPChannel(lProxy.__TransportChannel).Free; this is generating an AV
  TRoMessage(lProxy.__Message).free;

  TRoRemoteService(aILabelPrintingManagerIntf).Free;

我错过了什么?

4

1 回答 1

0

在与 RemObjects 的人讨论后,解决方案如下:

class function TLabelPrintingServiceProxy.GetRemoteServiceInstance: TRoRemoteService;
var
  LRoRemoteService: TRoRemoteService;
begin
  Result := TRoRemoteService.Create(nil);
  Result.Message := TROSOAPMessage.Create();
  Result.Channel := TROIndyHTTPChannel.Create(nil);
  Result.Channel.TargetUri := TROUri.Create(ILabelPrintingIntf.LabelPrintingManager_EndPointURI);
end;

称呼

try
  LLabelPrintingRemoteService := TLabelPrintingServiceProxy.GetRemoteServiceInstance();
  (LLabelPrintingRemoteService as ILabelPrintingManager).PrintVSSJob(printJob);
finally
  TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingRemoteService);
end;

并释放对象

try
  LLabelPrintingRemoteService := TLabelPrintingServiceProxy.GetRemoteServiceInstance();
  (LLabelPrintingRemoteService as ILabelPrintingManager).PrintVSSJob(printJob);
finally
  TLabelPrintingServiceProxy.ReleaseLabelPrintingServiceProxyInstance(LLabelPrintingRemoteService);
end;
于 2018-03-01T08:29:54.233 回答