Using a service within a thread

If I want to call a service from a client but within a secondary thread can I create an instance with:

var MySvc: IMySvc;

MySvc := CoMySvc.Create(aMessage, aChannel);

where the message and channel are in the main thread.

Or should I clone the Channel, Message and Server?

Thanks

you should to use another channel instance.
message can be cloned like

 lMessage := (ROMessage as IROMessageCloneable).Clone();

Thanks.

So:
create a new channel (something like NewChannel := MyChannel.ClassType.Create)
clone the message and assign the new channel to the massage.
It’s ok to use the same Server?
thanks

do you mean using it in statement like

MySvc := CoMySvc.Create(aMessage, aChannel);

it yes, this is ok.

Ok, so I am doing something wrong here as I get an invalid pointer operation when I call a service method. My code is like this. It is on a datamodule and ROLocalChannel and ROLocalMessage (TROBinMessage) are on the module.

lChannel := TROLocalChannel.Create(nil);
lChannel.ServerChannel := ROLocalChannel.ServerChannel;
lMessage := (ROLocalMessage as IROMessageCloneable).Clone();
lMessage.ClientId := ROLocalMessage.ClientId;

MySvc := CoMySvc.Create(lMessage, lChannel);

It seems that the Clone method does instantiate the Serializer when it gets to TROBinMessage.Initialize the call to Serializer to SetStorageRef has fSerializer = nil.

Any ideas?

I can’t reproduce this issue with simple testcase: testcase.zip (30.8 KB)

I’ll admit it’s a weird one. I’ve done a workaround for now, but will try and revisit when I have a moment.