Can I use Interface for CAO in Remoting?

和自甴很熟 提交于 2019-12-08 03:06:42

问题


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.

RemoteObject.IRemoteObject obj = (RemoteObject.IRemoteObject )Activator.CreateInstance(typeof(RemoteObject.IRemoteObject), null, url);

above code throws exception.


回答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.

I've used this technique on the job and it works well.



来源:https://stackoverflow.com/questions/1026140/can-i-use-interface-for-cao-in-remoting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!