Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending data to a website from a WCF service

I have the following setup

  • A jQuery website (not exactly single page, but not far from it), that uses a
  • A ASP.NET MVC website as a backend, which connects (via net.tcp or net.pipe) to
  • A self-hosted WCF service that manages and connects to
  • A plethora of high-latency external services.

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.

like image 866
SWeko Avatar asked Oct 12 '12 14:10

SWeko


3 Answers

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

like image 159
Jude Fisher Avatar answered Nov 18 '22 02:11

Jude Fisher


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.

like image 1
Paul Fleming Avatar answered Nov 18 '22 03:11

Paul Fleming


It sounds to me like you will need to implement some type in polling service to ping these external services for their availability.

like image 1
mojo722 Avatar answered Nov 18 '22 04:11

mojo722