XML Swagger documentation in service windows application

Hello, we have a problem em load XML documentation for swagger.

We have code:

procedure TServerContainer.XDataServerModuleCreate(Sender: TObject;
  Module: TXDataServerModule);
var
  LoggingMiddleware: TLoggingMiddleware;
  Compress: ICompressMiddleware;
begin
  TXDataModelBuilder.LoadXmlDoc(XDataServer.Model);

  XDataServer.SwaggerOptions.AuthMode := TSwaggerAuthMode.Jwt;
  XDataServer.Model.Title := sAPIMob;
  XDataServer.Model.Version := '1.0';
  XDataServer.Model.Description := 'test';

  Compress := TCompressMiddleware.Create;
  Compress.Threshold := 2048;
  Module.AddMiddleware(Compress);
  LoggingMiddleware := TLoggingMiddleware.Create;
  Module.AddMiddleware(LoggingMiddleware);
  Module.AddMiddleware(TJwtMiddleware.Create(sChaveJWT));
end;

This work when start with VCL application. But when start with windows service application code:
TXDataModelBuilder.LoadXmlDoc(XDataServer.Model);

generate access violation.

How can we generate documentation for Swagger with a windows service application?

Very hard to tell what's going on. I'd first suggest you pass the path to the XML files explicitly in the second parameter of LoadXmlDoc method.

I'd also ask you to debug the service to have an idea of what the line cause the Access Violation and what is the call stack at the moment of the error. There are some suggestions here: https://stackoverflow.com/questions/2884631/how-to-debug-a-windows-service-with-delphi.

Thanks! Find the problem.
The error is: Value: Microsoft MSXML is not installed

This happens only when I run the application as a windows service. Do you know which version of MSXML I have to install?

Hello, it worked using CoInitialize(nil);

  try
    CoInitialize(nil);
    try
      TXDataModelBuilder.LoadXmlDoc(XDataServer.Model);
    except
      on E: Exception do
      begin
        TnxLogArquivo.Singleton.AdicionaExcecao(E);
        raise;
      end;
    end;
  finally
    CoUninitialize
  end;

Thanks!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.