RAD Studio
|
To add a new Web Service interface to your server application, choose FileNewOther, and on the WebServices page double-click on the icon labeled SOAP Server Interface.
The Add New Web Service wizard lets you specify the name of the invokable interface you want to expose to clients, and generates the code to declare and register the interface and its implementation class. By default, the wizard also generates comments that show sample methods and additional type definitions, to help you get started in editing the generated files.
The interface definitions appear in the interface section of the generated unit. This generated unit has the name you specified using the wizard. You will want to change the interface declaration, replacing the sample methods with the methods you are making available to clients.
The wizard generates an implementation class that descends from TInvokableClass and that supports the invokable interface). If you are defining an invokable interface from scratch, you must edit the declaration of the implementation class to match any edits you made to the generated invokable interface.
When adding methods to the invokable interface and implementation class, remember that the methods must only use remotable types. For information on remotable types and invokable interfaces, see Using nonscalar types in invokable interfaces.
The Add New WebService wizard generates implementation classes that descend from TInvokableClass. This is the easiest way to create a new class to implement a Web Service. You can, however, replace this generated class with an implementation class that has a different base class (for example, you may want to use an existing class as a base class.) There are a number of considerations to take into account when you replace the generated implementation class:
You can tell the invocation registry how to obtain instances of your implementation class by supplying it with a factory procedure. Even if you have an implementation class that descends from TInvokableClass and that uses the inherited constructor, you may want to supply a factory procedure anyway. For example, you can use a single global instance of your implementation class rather than requiring the invocation registry to create a new instance every time your application receives a call to the invokable interface.
The factory procedure must be of type TCreateInstanceProc. It returns an instance of your implementation class. If the procedure creates a new instance, the implementation object should free itself when the reference count on its interface drops to zero, as the invocation registry does not explicitly free object instances. The following code illustrates another approach, where the factory procedure returns a single global instance of the implementation class:
procedure CreateEncodeDecode(out obj: TObject); begin if FEncodeDecode = nil then begin FEncodeDecode := TEncodeDecode.Create; {save a reference to the interface so that the global instance doesn't free itself } FEncodeDecodeInterface := FEncodeDecode as IEncodeDecode; end; obj := FEncodeDecode; { return global instance } end;
void __fastcall CreateEncodeDecode(System::TObject* &obj) { if (!FEncodeDecode) { FEncodeDecode = new TEncodeDecodeImpl(); // save a reference to the interface so that the global instance doesn't free itself TEncodeDecodeImpl->QueryInterface(FEncodeDecodeInterface); } obj = FEncodeDecode; }
InvRegistry.RegisterInvokableClass(TEncodeDecode);
InvRegistry()->RegisterInvokableClass(__classid(TEncodeDecodeImpl));
Add a second parameter to this call that specifies the factory procedure:
InvRegistry.RegisterInvokableClass(TEncodeDecode, CreateEncodeDecode);
InvRegistry()->RegisterInvokableClass(__classid(TEncodeDecodeImpl), &CreateEncodeDecode);
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|