Suppress WSDL-output for HttpServer

Hello

In my Delphi project I built a http server (TROBaseHTTPServer + TROSOAPMessage). There is a http dispatcher for http://localhost:xx/soap/MyWebAPI.

Sometimes I need to suppress WSDL output.

I know that the combination

ROBaseHTTPServer.ServeRodl := False
ROBaseHTTPServer.OnCustomResponseEvent := DoCustomResponseEvent;

allows to avoid WSDL-output and the server returns “Invalid Path” instead.

However, I would like to get more trasparent behaviour:

AvoidWSDL = False
http://localhost:xx/soap/MyWebAPI -> WSDL
http://localhost:xx/soap/MyWebAPI/<Method> -> method result
http://localhost:xx/soap/MyWebAPI/<unknownMethod> -> Invalid Path

AvoidWSDL = True
http://localhost:xx/soap/MyWebAPI -> Custom HTML (e.g. "WSDL is turned off")
http://localhost:xx/soap/MyWebAPI/<Method> -> method result
http://localhost:xx/soap/MyWebAPI/<unknownMethod> -> Invalid Path

Please, could you tell how I can implement this?

Best regards

You could override the TROBaseHTTPServer.ProcessRequest method.
There you can check the incoming request path and either let the channel process the request or provide own custom output (f.e. “WSDL is turned off”)

Hello

Somehow I expected more surgical touch :slight_smile: but the suggested approach works.
Thank you.

regards

btw, you could solve this via OnCustomResponseEvent event …

OnCustomResponseEvent event can be used only for cases when no dispatcher was found for an url. But I need to generate “WSDL is turned off” even when a dispatcher exists.

if SOAP message isn’t assigned to server, all WSDL requests will be processed via OnCustomResponseEvent event.

it means that to get the required behaviour I should do

ROBaseHTTPServer.ServeRodl := False;
ROBaseHTTPServer.OnCustomResponseEvent := DoCustomResponseEvent;

and aditionally find the dispatcher and reset its message (if it was assigned before)

SOAPDispatcher.Message := nil;

right?

yes.

you can just delete it from dispatchers, like:

untitled

yes, it’s a good solution for “static” cases but I need to turn off the feature at runtime.

Why you can’t process /soap requests in OnCustomResponseEvent event? I don’t think, that it will show critical slowness in comparing with usual way.

I’m not sure that I fully see your idea.
Please, could you give me a clue how to use OnCustomResponseEvent and not duplicate a lot of existing RO code?

simple code that works similar to registered dispatcher is

procedure TMegaDemoServerMainForm.ROIndyHTTPServer1CustomResponseEvent(
  const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse;
  var aHandled: Boolean);
var
  op: TROResponseOptions;
  b: TBytes;
begin
  if SameText(aTransport.PathInfo, '/mysoap') then begin
    aHandled := True;

    // place for custom checks

    MainProcessMessage((ROSOAPMessage as IROMessageCloneable).Clone,atransport,aRequestStream,aResponseStream,op);
    aResponse.ContentType := aTransport.ContentType;
  end;
end;

you can add any custom conditions, like checking for RODL/WSDL request:

    if aRequestStream.Size = 0 then begin
      b :=  StringToUTF8Bytes('WSDL is disabled');
      aResponseStream.Write( b, Length(b));
      Exit;
    end;

Thank you for so fast responces, Evgeny.
I will try to use these code snippets.

Best regards