In CAO there is no URI, so specified type has to be registered on the server side. But if my client and server interact through the same interface (remote object implements interface) then how can I call CAO remote object from client side. It gives me exception if I try to call Acitvator.CreateInstance using interface type. for e.g.
在CAO中没有URI,因此必须在服务器端注册指定的类型。但是如果我的客户端和服务器通过相同的接口(远程对象实现接口)进行交互,那么如何从客户端调用CAO远程对象。如果我尝试使用接口类型调用Acitvator.CreateInstance,它会给我异常。例如
RemoteObject.IRemoteObject obj = (RemoteObject.IRemoteObject )Activator.CreateInstance(typeof(RemoteObject.IRemoteObject), null, url);
above code throws exception.
上面的代码抛出异常。
2 个解决方案
#1
I'm not sure I can post a solution to your actual issue. However, I can explain why the code you've posted throws an exception. You are trying to create an instance of an interface type. This cannot be done, an interface contains no implementation. Generically speaking, I believe what you want to do is create the remote object type and the cast it to the interface that you want to be using (assuming the object implements the interface).
我不确定我是否可以针对您的实际问题发布解决方案。但是,我可以解释为什么您发布的代码会引发异常。您正在尝试创建接口类型的实例。这是不可能的,接口不包含任何实现。一般来说,我相信你想要做的是创建远程对象类型并将其强制转换为你想要使用的接口(假设对象实现了接口)。
#2
You might want to consider using the technique outlined in this MSDN article Implementing Broker with .NET Remoting Using Client-Activated Objects. This pattern uses a SAO factory to create CAOs.
您可能需要考虑使用本MSDN文章使用客户端激活的对象实现.NET Remoting实现代理中概述的技术。此模式使用SAO工厂来创建CAO。
I've used this technique on the job and it works well.
我在工作中使用了这种技术,效果很好。
#1
I'm not sure I can post a solution to your actual issue. However, I can explain why the code you've posted throws an exception. You are trying to create an instance of an interface type. This cannot be done, an interface contains no implementation. Generically speaking, I believe what you want to do is create the remote object type and the cast it to the interface that you want to be using (assuming the object implements the interface).
我不确定我是否可以针对您的实际问题发布解决方案。但是,我可以解释为什么您发布的代码会引发异常。您正在尝试创建接口类型的实例。这是不可能的,接口不包含任何实现。一般来说,我相信你想要做的是创建远程对象类型并将其强制转换为你想要使用的接口(假设对象实现了接口)。
#2
You might want to consider using the technique outlined in this MSDN article Implementing Broker with .NET Remoting Using Client-Activated Objects. This pattern uses a SAO factory to create CAOs.
您可能需要考虑使用本MSDN文章使用客户端激活的对象实现.NET Remoting实现代理中概述的技术。此模式使用SAO工厂来创建CAO。
I've used this technique on the job and it works well.
我在工作中使用了这种技术,效果很好。