简体   繁体   中英

Creating an XML document in Embarcadero RAD Server 10.3

I have an endpoint in the RAD Server which generates and returns an XML document. This code works just fine in a development environment. However, when I copy the bpl to the production server running on Apache on Windows, it returns a 500 error. I have figured out that is the code call to NewXMLDocument which is causing the error. I just don't know why it works on the development server but not on the production server and I don't know how to get any further diagnostic information from the production server.

The code is below and I have removed pieces of code that are not impacting the error. Does anyone have any ideas?

Edit: I was able to get a line further and now it is throwing the 500 error at: RootNode:= resultDoc.AddChild('root');

Solved: Found the issue was with MSXML on the server. Switched to Omnixml as default DOM vendor and everything seems to work. Thanks everyone.

procedure TQResource1.GetIMCansXML(const AContext: TEndpointContext;
  const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  sPlace      : String;
  resultDoc   : IXMLDOCUMENT;
  RootNode    : IXMLNODE;
  myStream    : TMemoryStream;

begin
  CoInitialize(nil);
  iNumRows := 0;
  Try
    Try
      SetDBConnection(AContext.User.UserName);
      myStream := TMemoryStream.Create;
      sPlace := '2';
      resultDoc := NewXMLDocument;
      sPlace := '3';
      resultDoc.Encoding := 'utf-8';
      resultDoc.Options := [doNodeAutoIndent];
      sPlace := '4';

      RootNode := resultDoc.AddChild('root');
      resultDoc.SaveToStream(myStream);
      myStream.Position := 0;

    Except
      on e1: exception do
      begin
        raise Exception.Create(e1.Message + ' @ ' + sPlace);
      end;
    End;

  Finally
    AResponse.Body.SetStream(myStream, 'application/xml', True);
    CoUninitialize;
  End;

end;

What I ended up doing was removing the msxml dependency by setting Omnixml as default DOM vendor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM