Suppress WSDL-output for HttpServer

delphi
wsdl
http

(Alexander Pustotin) #1

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


(antonk) #2

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”)


(Alexander Pustotin) #4

Hello

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

regards


(EvgenyK) #5

btw, you could solve this via OnCustomResponseEvent event …


(Alexander Pustotin) #7

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.


(EvgenyK) #8

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


(Alexander Pustotin) #9

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?


(EvgenyK) #10

yes.

you can just delete it from dispatchers, like:

untitled


(Alexander Pustotin) #11

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


(EvgenyK) #12

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.


(Alexander Pustotin) #13

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?


(EvgenyK) #14

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;

(Alexander Pustotin) #15

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

Best regards