how to send and recieve notification using WPF and WCF - wpf

I am using WPF and WCF for client server application. but i got a problem.
How to notify any update of client to other client.
Server(WCF)
Client1(WPF)
Client2(WPF)
if client1 enter any new record,immediatly notification send to client2 .
please suggest me best way to this complete task.
Thanks..

We have achieved such a requirement by using WCF Duplex Services. You can find enough information by googling about implementing a duplex service.
Basically;
clients send a client identifier (uniquely generated for each client) while registering to duplex service.
when WCF service updates data, pushes an update notification (including the notification source's client identifier) to all the registered clients
clients check for the originator's identifier when they got a notification. Discarding notifications caused by itself.
A few notes:
You can include everything about the updated data inside pushed notification payload to understand the change type or entity type.
Different bindings supported by duplex services. Usage of nettcpbinding is suggested if clients and service are in the same network and .net dependency is not a problem. You can find more information about support binding types from here or here.

Related

Wcf - using duplex - callbacks

I'm creating a wcf project with a wpf client using mvvm design pattern,
Where do I need to implement the ICallback interface so I will be able to update the
window.
The callback contract should be implemented on the client-side. Likewise, the service contract should be implemented on the server-side, with which the server can send data to the client-side by the callback contract.
Please refer to my example of the previous post.
TimeOut exception in WCF while implementing duplex
the client sends a parameter to the server by using the service interface, subsequently, the server sends the handled result to the client with the callback contract so that the client application gets the updated.
Feel free to let me know if there is anything I can help with.

Reconnecting WCF clients after a service receive timeout has occured

I have a WCF service which I host inside a WFP application, which acts as one of the clients of service as well. There is one more WPF app which acts as another client for service. After a timeout occurs and clients get disconnected, What is the proper way to clean up resources and connect the clients again. I am trying to create new proxies but I am not able to use them for communication. I know I can increase the recieve timeout on service but I need my clients to be able to communicate always not just for long enough. I have also tried continously sending a message to service at interval but that's something I don't want to go for. What approach is best for continous communication between clients and service? My service might need to be connected to clients for months or may be years.
Any help will be of great value.
Thanks in advance.
You can catch the CommunicationException or something like that and then restore the channel.

WCF: how to ensure if an updated was successful?

I have a WCF service, hosted in a win form application, that receive the requests from the clients. One of this requests, is update the stock of the items.
Well, my idea is to use a client to send to the WCF service the new amount of items, then the service use Entity Framework 4.1 to update the database with the new stock.
How the service is duplex, when the services has finished the update, it sends a message to the client to notify that the operations is successful. That's if there is no problems.
However, I have a question. It's possible that the client send the command to the service to update the stock. The service receive the command correctly, but before the operation is finished, the client lost the connection with the service, so the services can't send to the client the status of the operation, so the user does not know if it's all ok or not.
My second question has the same logic, but with the WCF service. It's possible that the WCF service is installed in other computer different to the computer in which is installed the database. So it's possible that the WCF services send correctly the command to the database, but before the database notify that the operation is successful, the WCF service lost the connection, so it never receive a response from the database but the operation is successful. How can the user know if the operation is ok or not?
So my question is, in WCF, how can I be sure that critical operations are successful or not?
Thanks.
Daimroc.

Silverlight notification from server to all clients without UDP

I wonder how can I achieve this without UDP, I have a solution using UDP multicast: http://blogs.msdn.com/b/ncl/archive/2009/11/18/udp-multicast-in-silverlight-4.aspx
but since this is for a high profile customer who has an intranet with port TCP 80 and TCP 8080 only enabled this solution is not possible. Yes, the application runs in an intranet environment.
I need a simple example how to send messages to all Silverlight clients over WCF.
I found this solution, but I have no idea how to implement that into Silverlight:
http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx
I'm out of ideas guys, please help.
Instead of receiving notifications async the Silverlight client should use polling instead.
It can poll a WCF service that will fetch the data from a db...
This is the typical solution. Anyway, you have to handle the case in which the Silverlight client wasn't online and then it becomes online and need to know its state...
However, if you still want Silverlight to receive async notifications try searching for 'Full Duplex'.
Here are some starting points:
http://blog.developers.ba/post/2009/02/25/Silverlight-chat-application-using-WCF-full-duplex.aspx
http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx
http://hindams.wordpress.com/2010/04/05/wcf-full-duplex-with-a-silverlight-application/

Can I implement callback from WCF based HTTP service to a gSOAP c/Linux client?

I have a Linux/c client app that connects to a WCF web service over HTTP/SOAP (BasicHTTPBinding). I am using gSOAP. Can I implement the calls to the web-service using callback? I want to get the data asynchronously as call back.
Update: I have updated the question title.
WCF does support Duplex services, or those that have the ability to call back to the requesting client. Duplex services can be very complicated, as they are not only stateful, but they impose an contract implementation requirement on their clients.
Duplex services require the use of the WSDuplexHttpBinding. You will need to make use of the OperationContext to get a reference to the callback channel. Your clients MUST implement the callback contract in some class, and provide an InstanceContext that contains an instance of the callback class to the client proxy. Communications in both directions must be supported, and if the client is behind its own firewall or across the internet, this can be a complicated matter to resolve. Take care when writing duplex services...they are often more trouble than they are worth...so make sure you really need it. ;-)
The following page might be helpful:
http://msdn.microsoft.com/en-us/library/ms731064.aspx
The basicHttpBinding does not support callbacks. Another approach might be to have another method that the client can poll on for the response.
I am facing the same issue and the approach I am trying is to have a pair of gsoap servers/clients. Basically each process will listen on a port for soap calls and make its client calls to the other server. This way I avoid the polling or other complex approaches. The code has to be obviously thread safe for whatever business logic is implemented but the client/server combo pair is the simplest solution i have thought of so far.
Obviously one needs to be in control of both sides of the solutions the mentioned server and the mentioned client.

Resources