Monday, October 25, 2004

Using TLinkedRio

If you need to test your webservices before they're deployed, you needn't build a client. To test your functions, simply create a TLinkedRio, and cast it to your interface. The TLinkedRio will also store the XML passed in files (for debugging)

For instance, for a procedure named Yawn in an exposed Interface IICancelWait:


function TICancelWait.Yawn: string;
begin
Sleep( 10000 );

Result := 'Excuse Me';
end;

To test it in the service itself, you can drop a button in the Server form (this is a WAD project) and a label, with the following code in the button's handler:

procedure TForm1.Button1Click(Sender: TObject);
var MyRio : TLinkedRio;
begin
// use a TLinkedRIO

MyRio := TLinkedRio.Create(nil) ;
Label1.Caption := (MyRio as IICancelWait).Yawn;
end;

Notice that you don't need to free MyRio. A TLinkedRio will automatically get freed when it goes out of scope, if the Owner is null.

All you have to do is include the SoapLinked unit and the interface units in your server project.

You can even store the Request and Response in XML files to check the XML formatting or for other validations. Instead of Create, call CreateFile.


MyRio := TLinkedRio.CreateFile(nil,
ExtractFilePath(Application.ExeName)+'Req.xml',
ExtractFilePath(Application.ExeName)+'Resp.xml');

Note: Application.ExeName will only work for WAD executables. You need to use GetModuleFileName for ISAPI dlls, instead of Application.ExeName.

3 Comments:

Blogger Chris Miller said...

Is this limited to WAD executables or can you use Indy based soap executables? I'm writing a web service in Delphi 7 using the Indy IdHTTPWebBrokerBridge to run the web service without a web server. I can compile the service as an application and it would be nice to be able to try this technique.

8:12 AM  
Blogger Deepak Shenoy said...

Oh yes, what I meant was: Application.ExeName will only work for WAD Executables. TLinkedRio will work with Indy based SOAP Exes too.

8:37 AM  
Blogger Chris Miller said...

I finally got around to using TLinkedRio in my Indy based service. It worked great. Thanks for this tip, it will greatly speed up my unit testing for this service.

11:39 AM  

Post a Comment

<< Home