How we use CallBack in WCF fluently with events and delegates?
If Client give any request or any conditions matches of client then services automatically fire the event which condition or request given from client.
how is it possible?
A cleaner model is an event driven one using a Publish/Subscribe Pattern.
Read this to get inside onto both methods.
http://msdn.microsoft.com/en-us/magazine/cc163537.aspx
You basically define a service method as one-way and also create a message callback. See more here: http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx
Related
I am using CQRS with EventSourcing.
I have to use SignalR for updating grid when particular event raised in all opened browsers.
So, I have to push data to all clients once Particular event raised.
Currently when user manually refresh page the query is fired which is pulling the data, but I have to pull data without manual refresh using SignalR.
I am new to SignalR, Can I get any sample code/reference for implementing the same?
You could read this article about this topic.
There is also a public repository with some "basic experimentations" with CQRS+ES and SignalR.
Hope this helps
First, you must create a Hub class so clients can connect to.
Then, in your event handler you do:
var hubContext = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
hubContext.Clients.All.callJavaScriptFunction(parameters);
This way, when the event handler gets executed, SignalR will call the client methods you want with the data you provide.
You must also create the proper connection from the client and define callJavaScriptFunction.
Note: If you are using dependency injection, you might see very unstable behavior from GlobalHost. Let me know if it is the case.
Hope this helps!
Best of luck!
I have a WinForm client that its using WCF DataServices. I would like to know if WCF DataServices has some kind of BeforeSendRequest and AfterSendRequest so I can show on the UI an icon that some database request its running.
Any clue?
Thanks
Unfortunately WCF doesn't have anything like Global.asax where we can handle BeginRequest and EndRequest
Based on your question, I guess the interface IClientMessageInspector will be handy.
The methods to be implemented will be BeforeSendRequest and AfterReceiveReply. I guess these are the two events you are looking for.
The documentation regarding this is available in the following msdn link
http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx
In short, you will have to implement the IClientMessageInspector( part of System.ServiceModel.Dispatcher) and also implement IEndpointBehavior (part of System.ServiceModel.Description) to hook the inspector on to the client endpoint. And thus change the configuration in the client endpoint to refer the endpoint behaviour that was added.
While trying to implement asyncronous email over smtp in my ASP.Net MVC 3 application I've come around SO SmtpClient.SendAsync blocking my ASP.NET MVC Request thread. There I found the article by Phil Haack: The Dangers of Implementing Recurring Background Tasks In ASP.NET which provides a way to avoid crashing of the background thread on AppDomain shutdown.
The article says to call HostingEnvironment.RegisterObject(this); on the constructor and call HostingEnvironment.UnregisterObject(this); only if IRegisteredObject.Stop Method is called.
In a general scenario, when requests arrive permanently, and the scope of the object implementing IRegisteredObject is request, dosn't this approach register objects within each request (utilizing the email functionality) and does not unregister any?
Is it OK? Or should I also unregister after the asynchronous operation completed?
P.S.: as suggested by Damian Edwards in the linked SO question, I use ThreadPool.QueueUserWorkItem to send the email beyond request scope.
I'm not sure what you mean by requests arrive permanently, scope of the object ... is request etc.
Request Scope, permanent, and ThreadPool.QueueUserWorkItem; these words together do not make sense at all. One uses ThreadPool.QueueUserWorkItem so that a request does not take forever. The time-consuming job is done in the background while your request returns immediately as Damian Edwards suggests.
I have used IRegisterObject to send bulk e-mails upon a request received. However, in my case, I have used a singleton object EmailSender that implements IRegisterObject. In that case, it is registered once in the constructor and unregistered once in Stop().
So, in short, please use a singleton.
I have a service that does image processing. The time that it takes for the process to complete is something like 2-3 minutes.
Can I update the client with the progress of the service? can I somehow tell the client that process reached step3 or something like that?
I am using WCF
You can look at the duplex bindings, which supports two way communication:
http://msdn.microsoft.com/en-us/library/ms731064.aspx
It works using a callback mechanism.
Sure you can. Use some asynchronous method of WCF to get image processing % value. I mean you have to create this method. And on the client side you have to call this method periodically.
This is baked into a couple of the .NET assemblies. Have you looked at the WebClient class for example? There are *ProcessChanged event handlers, like DownloadProgressChanged.
Just add these in and wrap them around your methods that take time, e.g. ProcessImage().
Hallo again my question regards to event based model client development in WCF service client infrastructure. what I would lice to know is that, instead of using ClientBase is it possible to manually implement this patten with ChannelFactory so for example I could write GetDataAsync for client access and still using ChannelFactory and implementing serverside async calls here?
The answer will depend on whether you control the service contract or not. If you can define the service contract then you add the appropriate begin/end methods that return/use the IAsyncResult as shown in the code in this blog post.
If you can't change the service contract then you must create an async version of the service contract manually and feed that to the ChannelFactory. The ChannelFactory itself does not provide an async mode of service operation invocation. Your code will end up looking something like the code in this MSDN sample.