Instantiating CAO without using new operator

  • Thread starter Abhishek Srivastava
  • Start date
A

Abhishek Srivastava

Hello All,

I want my clients to use my remoted object by means of interfaces. These
interfaces also ensure clean seperation between client and server.

The approach I know to instantiate a CAO is

RemotingConfiguration.RegisterActivatedClientType(
typeof(MyObject),
"tcp://localhost:1234/MyServer");
MyObject obj = new MyObject();

But I cannot do this because I am using an Interface for the client to
invoke the method on the server.

How to have an interface based client server coupling when using CAOs?

Thanks for your help in advance.

regards,
Abhishek.
 
A

Abhishek Srivastava

I have already tried Activator.CreateInstance method. But it does not work.

The error message that will appear is

Unhandled Exception: System.MemberAccessException: Cannot create an
instance of an interface.
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Client.Main(String[] args)

I am not providing the implementation of the remote object to the
client. The client binds only to the interface being implemented by the
remote object.

I found a solution which involves using soapsuds. However it works only
for the http channel whereas I want to use tcp channel.

regards,
Abhishek.
 
S

Sunny

Hi,
can you post your CreateInstance line?

Also, you do not have to call RegisterActivatedClientType before that.

Sunny

abhishek- said:
I have already tried Activator.CreateInstance method. But it does not work.

The error message that will appear is

Unhandled Exception: System.MemberAccessException: Cannot create an
instance of an interface.
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Client.Main(String[] args)

I am not providing the implementation of the remote object to the
client. The client binds only to the interface being implemented by the
remote object.

I found a solution which involves using soapsuds. However it works only
for the http channel whereas I want to use tcp channel.

regards,
Abhishek.

Madhu said:
Hi Abhishek,

Check out the Activator.CreateInstance method. This method can be used to create the instance of CAO using interface.

Take a look at the following links,

<http://msdn.microsoft.com/library/d...rfsystemactivatorclasscreateinstancetopic.asp>

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/introremoting.asp>

Hope this helps...
 
N

Nicholas Paldino [.NET/C# MVP]

Abhishek,

You should call the version of CreateInstance which takes an array of
objects to use as activation attributes. The attribute that you will want
to pass is an instance of UrlAttribute, which specifies where the object
will be activated. Then, you have to unwrap the ObjectHandle that is
returned, and then cast that to the interface.

There is an example in the documentation for CreateInstance.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Abhishek Srivastava said:
I have already tried Activator.CreateInstance method. But it does not work.

The error message that will appear is

Unhandled Exception: System.MemberAccessException: Cannot create an
instance of an interface.
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Client.Main(String[] args)

I am not providing the implementation of the remote object to the
client. The client binds only to the interface being implemented by the
remote object.

I found a solution which involves using soapsuds. However it works only
for the http channel whereas I want to use tcp channel.

regards,
Abhishek.

Madhu said:
Hi Abhishek,

Check out the Activator.CreateInstance method. This method can be used to create the instance of CAO using interface.

Take a look at the following links,
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemactivatorclasscreateinstancetopic.asp><http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/h
tml/introremoting.asp>
Hope this helps...
 

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

Top