BindingList over Remoting using an interface type

G

Guest

This works without any problems:

Code Snippet

string uri = "tcp://localhost:8000/CAOFactory";
cf =
(CustomerInterfaces.ICAOFactory)Activator.GetObject(typeof(CustomerInterfaces.ICAOFactory), uri);

ICustomer objCustomer = cf.CreateCustomer();
BindingList<ICustomer> customers = objCustomer.GetCustomers();

My form has a binding source and I set its DataSource property to the
customers object. The form also has a Binding Navigator which pulls form that
BindingSource.

If I set the AllowNew property on the customers list to true I get the "+"
icon on the BindingNavigator. Exactly what I want.

However, when I click that icon it attempts to make a new object of the
interface type ICustomer. Obviously not possible.

So, I handle the AddingNew event of the list with this:

void customers_AddingNew(object sender, AddingNewEventArgs e)
{
e.NewObject = cf.CreateCustomer();
}

Sadly, that gives me the error:

"Because of security restrictions, the type System.Runtime.Remoting.ObjRef
cannot be accessed."

I've read up on this err and found that if you change the typeFilterLevel of
your remoting formatter it would work. I'd prefer not to do that.

Info on that was found here:
http://www.thinktecture.com/resourcearchive/net-remoting-faq/changes2003

If they changed this behavior in .Net 2.0 than it was probably for a good
reason. There has to be another way to do this? Is it not best practice to
code towards interface types? What's the solution for dynamic lists over
remoting when using interface types?

-Mike.
 
N

Nicholas Paldino [.NET/C# MVP]

The reason they did it was for security reasons. I forget the exact
reason why, but searching for that error should bring up some articles
detailing the security issues.

I think the larger issue here is that you are connecting the list and
making changes to it over remoting. It seems that you are binding the list
in the UI to objects hosted on the server, which seems very wasteful, since
every call to every method/property on any of the instances referenced by
the interfaces generated by the factory is going to result in a call back to
the server. Generally speaking, this is not a good thing for distributed
calls.

It seems like you are simply adding/editing/deleting new instances of
the type. I would recommend using a concrete, serializable type here, and
then performing the updates on the list as a whole (you would send the whole
list back with any additions, edits, and deletes in one shot to the server
to process). This would certainly get around the issue, since you would no
longer be using remotable types (at least for the items in the list).
 

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