Ambiguity with ContextID in entprise services.

  • Thread starter Thread starter Michael Nemtsev
  • Start date Start date
M

Michael Nemtsev

Can't ace in how client and server component contexts correspons with
each other.
Server-side (entperiseServices) component is always created in context.
But I'd like to create serverside component in *client context*, and
therefore contextID of the client and server should be the same. For
unknown reasons, I got different context ID (albeit sync options are
the same)

Who can clarify this and say how to create server side component in
client context?

I use such code for client

static void Main(string[] args)
{
// Define context attributes
ServiceConfig config = new ServiceConfig();
config.Synchronization = SynchronizationOption.Required;

// Create client context
ServiceDomain.Enter(config);
// Show client context ID
Console.WriteLine(ContextUtil.ContextId.ToString());

// Create server side component
Class1 cl = new Class1();
// Show server side component's contextID
Console.WriteLine(cl.State());
}

Code for server component

[EventTrackingEnabled]
[Synchronization(SynchronizationOption.Required)]
public class Class1: ServicedComponent
{
public Class1()
{
}

public string State()
{
return "Activity: " + ContextUtil.ActivityId.ToString() + "
Context: " + ContextUtil.ContextId.ToString() + " Instance: " +
ContextUtil.ApplicationInstanceId.ToString();
}
 
Michael,

Just curious, are you registering this as in process or out of process?
If it is out of process, then the context is always going to be different.
 
I use ActivationOption.Library - that's why I'm so confused.
PS: I use FW 2.0

Could u try by yourself? What's your results? The same contextID?
 
Interestingly, using attibute [MustRunInClientContext] gives an error
"Unhandled Exception: System.Runtime.InteropServices.COMException
(0x80004024): The specified activation could not occur in the client
context as specified. (Exception from HRESULT: 0x80004024)"

Scrutinizing options of my component in ComponentServices Browser I've
noted that in Activation tab I have option
"Don't force activation context" is checked ON. After checking ON "Must
be activated in caller context" instead - all works fine, the contexts
ID are the same.

Nickolas, could u make this clear?
PS: Is it possible to turn on this feature by attibute?
PPS: Aren't "MustRunInClientContext" and "Must be activated in caller
context" the same?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top