.NETGURU
Remoting exception when using interfaces
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.remoting.

Post a new message to this list...

Henke
Hi!
I have a 3-tier solution that uses remoting from the business logic layer to
the data access layer. Every business manager object implements an interface
that is used by the ASP.NET clients to communicate with the business logic.
Ie I have a CustomerManager object and a ICustomerManager interface. Only my
interface assembly is distributed with the client.

I "create" my managers in the client by calling:
ICustomerManager cm
=(ICustomerManager)Activator.GetObject(typeof(ICustomerManager), url);

When I try to call a method on the cm instance I get an exception:
"Attempted to create a well-known object of type
ICustomerManager. Well known objects must derive from the
MarshalByRefObject."

The implementation of the CustomerManager looks like this:
public class CustomerManager : MarshalByRefObject, ICustomerManager
{
...
}

What am I doing wrong, I don't want do distribute my manager assemblies, but
just the interface assemblies?

Thanks in advance!
/Henke

Reply to this message...
 
    
Ken Kolda
Can you show the server-side code you use to register the well-known object?

Ken

"Henke" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Henke
Yes, here it is:
TcpChannel channel = new TcpChannel(2099);
ChannelServices.RegisterChannel(channel);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(ICustomerManager),
"RemoteServer",
WellKnownObjectMode.SingleCall);

/Henke

"Ken Kolda" <Click here to reveal e-mail address> skrev i meddelandet
news:%Click here to reveal e-mail address...
> Can you show the server-side code you use to register the well-known
object?
[Original message clipped]

Reply to this message...
 
    
Ken Kolda
Ahh.. there's your problem. When you cann RegisterWellKnownServiceType, you
have to pass it a class Type, not an interface (after all, the remoting
framework has to know what type to instantiate to fulfill the remoting
requests it receives). Just change your call to use CustomerMnager instead
of ICustomerManager. From the client side, it will still just use
ICustomerManager and does not need the CustomerManager implementation, so
you've still achieved the separation you want.

Ken

"Henke" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Robert Jordan
Ken Kolda wrote:

[Original message clipped]

BTW, a stub implementation of CustomerManager can be generated
with SoapSuds.exe. You should always deploy the stub with the
clients instead of the real implementation.

bye
Rob

[Original message clipped]

Reply to this message...
 
    
Ken Kolda
By using interface-based remoting no stub is necessary -- he just deploys
the assembly containing the interface definition. Creating a stub via
SoapSuds is alternative to using interfaces (although I've never seen the
advantage to it).

Ken

"Robert Jordan" <Click here to reveal e-mail address> wrote in message
news:ci4o7r$t8u$03$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Robert Jordan
Hi Ken,

[Original message clipped]

Well, as you stated before: a class type is required to be able
to instantiate the CAO, and that type must implemenent the
certain interface. You have 2 choices: deploy the whole
implementation (bad) or deploy the stubs.

[Anyway, I'd go for the 3rd way: singleton with factory
pattern]

bye
Rob

[Original message clipped]

Reply to this message...
 
    
Robert Jordan
Hi Ken,

sorry, forget it. I obviosly didn't read the OP ;-)

bye
Rob

[Original message clipped]

Reply to this message...
 
    
Henke
Hi, and thanks for your answers. Now it works!
But I have an other question.
For easier debugging I had a ObjectHandler that when in production 'creates'
the object by calling Activator.GetObject(typeof(CustomerManager), url), and
when in development

System.Reflection.Assembly a =
System.Reflection.Assembly.GetAssembly(CustomerManager);
object obj = a.CreateInstance(CustomerManager.ToString());

Now that I have changed to interfaces I can't use the CreateInstance method
anymore any good ideas about this problem?

/Henke

"Ken Kolda" <Click here to reveal e-mail address> skrev i meddelandet
news:%23$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Ken Kolda
You can still use CreateInstance(), just pass it the name of the class as a
literal string (instead of using Type.ToString()), e.g.

ICustomerManager mngr = (ICustomerManager)
assembly.CreateInstance("MyNamespace.CustomerManager");

Ken

"Henke" <Click here to reveal e-mail address> wrote in message
news:OYTWH%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Henke
Ok, thanks Ken. I have to do a litle parsing method that parses my
interfaces to class names than.
/Henke

"Ken Kolda" <Click here to reveal e-mail address> skrev i meddelandet
news:Click here to reveal e-mail address...
> You can still use CreateInstance(), just pass it the name of the class as
a
[Original message clipped]

Reply to this message...
 
 
System.Activator
System.MarshalByRefObject
System.Reflection.Assembly
System.Runtime.Remoting.Channels.ChannelServices
System.Runtime.Remoting.Channels.Tcp.TcpChannel
System.Runtime.Remoting.RemotingConfiguration
System.Runtime.Remoting.WellKnownObjectMode
System.Type




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification