ServiceBuilder Code generation

Hi,

My call GetScenarioDocumentInstructions is defined as follows:

In Service Builder 9.7.115.1441, CodeGen generates his (Delphi) implementation:
function GetScenarioDocumentInstructions(const Scenario: Integer; const Document: ROUTF8String; const DocumentLanguage: Integer): ROUTF8String; virtual;

Note that the “UnitNumber” input parameter is missing.

When I do a CodeGen (C# for .NET) I get a correct function in implementation
public virtual string GetScenarioDocumentInstructions(int Scenario, string Document, int DocumentLanguage, string UnitNumber)

When I do a CodeGen (Delphi) with Service builder version 9.6.113.1419 I also get a correct function in implementation:
function GetScenarioDocumentInstructions(const Scenario: Integer; const Document: ROUTF8String; const DocumentLanguage: Integer; Const UnitNumber: ROUTF8String): ROUTF8String; virtual;

When I rename the result parameter to UnitNumber2, the function in the implementation file is created correctly. However, I can’t just rename this because this breaks functionality in our client apps.

How can I solve this? Is there a solution?

Hi,

I’ve tried this case:


looks like it works as expected with the latest version (v10.x):

  INewService = interface(IROService)
  ['{4ADE3665-D237-4646-9D9B-625F3C320B23}']
    function NewMethod(const NewParam: ROAnsiString): ROAnsiString;
  end;

Thanks, the Code Generation works as expected in 10.0.0.1521

But now I run into another problem (not present in v 9.7): when making a call from a browser I get a CORS error:

Access to XMLHttpRequest at ‘X’ from origin ‘Y’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

The component I use is a TROIndyHTTPServer and SendCrossOriginHeader is set to true
afbeelding

In fact, combined with version 9.7 the same project worked flawless.

How can I solve this?

Hi,

Check OnSendCrossOriginHeaderEx event of TROIndyHTTPServer.

Hi,

It’s empty. Do I have to put something there?

Hi,

you can assign your own values to those values:

function TForm3.ROIndyHTTPServer1SendCrossOriginHeaderEx(
  var Cors: TROCorsStruct): Boolean;
begin
  // Cors.Origin
  // Cors.AllowedOrigin :=
  // Cors.AllowedMethods :=
  // Cors.AllowedHeaders :=
  // Cors.MaxAge :=
end;

Evgeny,

I defined cors like this, but the error message “No ‘Access-Control-Allow-Origin’ header is present on the requested resource.” keeps popping up.

function TdmServer.svrHTTPSendCrossOriginHeaderEx(
var Cors: TROCorsStruct): Boolean;
begin
Cors.AllowedOrigin := ‘*’;
Cors.AllowedMethods := ‘GET, POST, PUT, MERGE, DELETE, HEAD, OPTIONS’;
Cors.AllowedHeaders := ‘Content-Type, User-Agent, Authorization, Access-Token, X-Requested-With’;
Cors.MaxAge := 86400;
end;

Perhaps it might help you, but when I compile the project with remoting SDK 9.6 or 9.7 there is no CORS problem, even without this SendCrossOriginHeaderEx event.
Did something change in version 10 that could impact CORS handling?

Hi,

can you confirm that cors setting are set correctly in server response, pls?

Evgeny,

How can I do that?

Hi,

you can see response headers with curl or similar tool.

Evgeny,

The project was compiled with version 9.7 and 10.0.

In both version 9.7 and 10.0, TROIndyHTTPServer’s property SendCrossOriginHeader is True.

In version 10.0, I added this piece of code to make sure CORS info was added:

function TdmServer.svrHTTPSendCrossOriginHeaderEx(
var Cors: TROCorsStruct): Boolean;
begin
Cors.AllowedOrigin := ‘*’;
Cors.AllowedMethods := ‘GET, POST, PUT, MERGE, DELETE, HEAD, OPTIONS’;
Cors.AllowedHeaders := ‘Content-Type, User-Agent, Authorization, Access-Token, X-Requested-With’;
Cors.MaxAge := 86400;
end;

Then, I used postman to check the headers.

In version 9.7, these are the response headers:

In version 10.0, these are the response headers:

The only difference is the “Access-Control-Allow-Origin” header that is missing in 10.0

Patrick

Evgeny,

When I downgrade from version 10.0.0.1521 to 10.0.0.1457, my CORS problem dissapears.
This version doens’t have OnSendCrossOriginHeaderEx, but even with an empty OnSendCrossOriginHeader the header “Access-Control-Allow-Origin = *” is showing in the response (because of the SendCrossOriginHeader property set to true).

For now, I will stick with the 10.0.0.1457 version. This version does the expected.

But my initial problem, that CodeGen generates an incorrect implementation file when an input and output parameter have the same name (only in Delphi, in C# it is correct) isn’t solved in this version.

generates this function in the implementation file:

function Test(const Hello: ROUTF8String): ROUTF8String; virtual;

Notice the Evgeny input parameter is missing.

When I rename the input parameter to EvgenyK the function is properly generated:

function Test(const Hello: ROUTF8String; const EvgenyK: ROUTF8String): ROUTF8String; virtual;

How can this get solved?

Patrick

Hi,

I can’t reproduce CORS issue:

>curl -verbose -X OPTIONS "http://localhost:8099/bin"
*   Trying ::1...
* TCP_NODELAY set
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8099 (#0)
> OPTIONS /bin HTTP/1.1
> Host: localhost:8099
> User-Agent: curl/7.56.0
> Accept: */*
> Referer: rbose
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Accept-Encoding: gzip, identity
< Access-Control-Allow-Origin: *
< Access-Control-Max-Age: 86400
< Connection: keep-alive
< Content-Length: 0
<
* 
Connection #0 to host localhost left intact

as for me, it returns Access-Control-Allow-Origin header


you can install the latest RON over existing ROD. it will install the latest codegen

I installed the latest of RO Remoting SDK for .NET, version 10.0.0.1521

However, when I try to compile my project I get errors in the generated interface file:
[dcc32 Error] RAC_Intf.pas(12598): E2003 Undeclared identifier: ‘TROAsyncCallbackMethod’
That is because the versions of ServiceBuilder and RO should match.

By trial and error, I found that version 10.0.0.1495 solves both problems: CORS and CodeGen are OK now. Let’s hope I don’t need to upgrade soon :slight_smile: