I have the following setup
So when a client pushes a button, a request is sent to the MVC, which routes it to the WCF, which aggregates it from the external services, and everything is fine and dandy.
The issue I can't seem to wrap my head around is communication in the other way, i.e. when one of the external services goes offline, what is the easiest and most elegant way to inform the client (the browser)?
This means that the service should somehow inform the mvc site that should somehow inform the client that an external service is offline.
Additionally: The external service will have high availability, so the "goes offline" scenario will be seldom used, and accordingly I'm looking for a solution that does not do extensive polling of the server.
I'm working on a similar architecture and am planning to use SignalR to push updates from WCF, (sometimes directly, sometimes via Azure Service Bus), to a single-page jQuery-driven app. I haven't implemented this yet, though, so there may be some issues I haven't considered.
From their docs:
Pushing data from the server to the client (not just browser clients) has always been a tough problem. SignalR makes it dead easy and handles all the heavy lifting for you.
Scott Hansleman has a good blog on the topic here: http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
You can use fault exceptions to return exception data to the client.
I prefer to have an IsSuccessful
flag on my returned contracts and only throw fault exceptions when there's a critical error.
Here's a very basic example of a response contract with an IsSuccessful
flag.
[DataContract]
public class MyResponse
{
[DataMember]
public bool IsSuccessful { get { return Message == null || !Messages.Any(); } set { } }
[DataMember]
public List<string> Messages { get; set; }
}
Messages
can be complex types if you need to provide more detailed information. DataContract
and DataMember
attributes can be MessageContract
and MessageBodyMember
if that suits your architecture better.
It sounds to me like you will need to implement some type in polling service to ping these external services for their availability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With