开发者

delegates across different machines

开发者 https://www.devze.com 2023-03-21 19:10 出处:网络
it seems like it should be dead easy, but i couldn\'t find anything in google on it: I have a video store server, and it has multiple client applicat开发者_开发问答ions, installed on users\' machines,

it seems like it should be dead easy, but i couldn't find anything in google on it:

I have a video store server, and it has multiple client applicat开发者_开发问答ions, installed on users' machines, communicating via (let's say) web services.

When a DVD is returned, I'd like to be able to notify useres that have been waiting for that DVD.

When dealing with a single application, then that's no problem using delegates.

my question is- can this approach work with remote clients as well?


You can use a duplex WCF service for that.

But if it really is a DVD handling service where the user doesn't need to be notified immediately, I would recommend a solution where the users' clients poll the server every say 10 minutes. It is far more simple to implement.


Yes - you can use .NET remoting. See this article for a simple example:

http://www.codeproject.com/KB/IP/remotingandevents.aspx


If you want to have a client application that will provide a delegate that people can wire up to, then yes. You would use .net remoting for that.

I used this example: http://www.codeproject.com/KB/dotnet/DotNetRemotingEventsExpl.aspx

Basically what you are going to do, is to expose a remoting server that publishes a known object. The trick with events, is that the server has to know about the type that the client is wiring the event handlers to. So what you do in that case is that you also provide an abstract class as an event sink.

Basically that class will look something like this:

public abstract class MyEventSinkClass : MarshalByRefObject
{
   public abstract void MyAbstractEventHandler(string arg1, string arg2);

   public void MyEventHandler(string arg1, string arg2)
   {
       MyAbstractEventHandler(arg1,arg2);
   }
}

Then on the client side they would create a class, and inherit from MyEventSinkClass. They put their logic for handling the event in the override for MyAbstractEventHandler. When they wire up the instance that they are using remoting for, instead of wiring like you normally would, they need to wire to their instance of the class that inherits MyEventSinkClass to the MyEventHandler Method. Then when the event fires, it will eventually call into the overriden method and execute their code.

You can find the details of how to setup a remoting server and client in the link I gave, it isn't difficult.


If you don't want to invent the wheel, Use a Message Queuing tool. Then, when a dvd is return you post a message on some queue. The users are registering to the queues of the DVDs they are interesting in.

Then the communication is persistent and async. the users are getting notifications even if they are offline (they'll get it once they connect and poll the queue)

0

精彩评论

暂无评论...
验证码 换一张
取 消