0

Here is my situation: I have a Firebird database, a WCF REST service (.NET 4.5) and a Windows Mobile 6 client. What I need is: on Firebirds post event, WCF REST should notify the client.

I know that WCF has duplex communication when used as SOAP service, but I can't use it due framework version incompatibilities. Any ideas? Is this even possible and if not are there any alternatives? I'm generally new to WCF so I'm probably missing something, but I couldn't find anything helpful for my particular situation.

P.S If you need code snippets from my service let me know. There is a lot of it and I'm trying to keep this post as clean as possible.

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
Aleksandar
  • 246
  • 1
  • 10

2 Answers2

0

I would use ASP.NET Web API 2 over WCF for developing Rest services and SignalR.

Web API would be for your REST web services and SignalR to notify all your clients when Firebird posts an event.

SignalR allows bi-directional communication between server and client.

Sample Hub:

public class SomeHub: Hub
{
    public void Send(string name, string message)
    {
        Clients.All.broadcastMessage(name, message);
    }
}
William Xifaras
  • 4,799
  • 2
  • 15
  • 19
  • This isn't going to work for me because SingalR's client isn't supported on windows .net CE, although still useful suggestion for future projects. – Aleksandar Oct 12 '16 at 10:20
0

I found solution, but i'm not entirely sure how good it is. First i made WCF method that is used to "Subscribe" to events

Interface declaration

 [OperationContract]
 [WebInvoke(Method = "GET",
 BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Notification")]
 Stream Notification();

Service class implementation

public Stream Notification()
{
        string result= "";
        using (FbConnection conn= new FbConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
        {
            conn.Open();
            FbRemoteEvent events= new FbRemoteEvent(conn, "event1", "event2", "event3", "event4");
            events.QueueEvents();
            AutoResetEvent waitHandle = new AutoResetEvent(false);
            eventi.RemoteEventCounts += (sender, args) => 
            {
                if (args.Counts > 0)
                {
                    result= args.Name;
                    waitHandle.Set();
                }
            };
            waitHandle.WaitOne();
        }

        return new MemoryStream(Encoding.UTF8.GetBytes(result));
}

I'm using AutoResetEvent to freeze service instance until post_event happens and once it does happen AutoResetEvent's Set() method is called to unfreeze service and return in my case events name, so i know which event triggered. On client side i'm calling this method in seperate thread and waiting for its response, once i get it i process it accordingly and resend same method request again so i can catch next post_event.

P.S. You should set your InstanceContextMode to PerCall for this to work.

Aleksandar
  • 246
  • 1
  • 10