none
How to call a dualHttpBinding(callback contract) from a webHttpBinding service in WPF RRS feed

  • Question

  • Hi all I am facing one issue with dualHttpBinding and webHttpBinding in my application. Here is the overall scenario

    I have a dotNet and Android application which consumes a WCF Service (which has three different bindings).

    1. basicHttpBinding - For dotNet app (Service1.svc)
    2. webHttpBinding - For Android to access via Rest full service (Service2.svc)
    3. dualHttpBinding - For push notification to dotNet app(PushServie.svc)

    When ever android app consumes a method in Servie2(AddOrderItems) - it inserts into database and in inturn shows a message in dotNet application (a push notification). For this I have used CallBackContract in PushService and it is working fine when I try to access the AddOrderItems method (in Servie2) from dotNet app (for testing purpose I did) and notification message is coming.

    But my problem is how can I come to know whether and and when my AddOrderItems is being called from android app, so that I have to show a message (via CallBackContract) in dotNet app.

    I tried to call PushServie.svc method(CallBackMessagge) from Servie2.svc after calling AddOrderItems method but no luck at all.

    Here is the code for Service2 and PushService.svc

    AddOrderItems method in IService2 which is implemented in Servie2.svc [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "AddOrderItems", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] bool AddOrderItems(RequestOrderItemData orderItemData);

    and call back method in IPushService which is implemented in PushService.svc

        [OperationContract(IsOneWay = true)]
        void DisplayMessage(int orderID, int tableID, string tableName);

    Here is the code for DisplayMessage in PushService

     IPushNotificationCallBack Callback
        {
            get
            {
                return  
                OperationContext.Current.GetCallbackChannel<IPushNotificationCallBack>();
            }
        }

    and the method in PushService.svc

    public void DisplayMessage(int orderID, int tableID, string tableName)
    {
       Callback.DisplayMessage(orderID, tableID, tableName);
    }

    I tried to search in googles and every one says that a webHttpBindin does not support a callback functionality.

    My concern is I want to call my DisplayMessage method from AddOrderItems. If this can be possible with any modifications, I am really be in happy.

    As far as I think I have posted all the necessary code, if some thing else requires, please let me know, I will post it.

    Any help highly appreciated.

    Warm Regards,

    Ganesh


    Thanks Ganesh Kumar Poosarla

    Friday, October 3, 2014 7:36 PM

Answers

  • Hello Ganesh,

    1. You need to re factor the architecture like below.

    Over the DB, User entity framework or some other API to give you save notifications. That means whenever your DB inserted new orders you get a notification to your Implementation (DB handling code).

    2. Now build a service "PushService" with callback contract "ClientContract". Your .net client implement this client contract and subscribe to the "PushService" in order to get call backs. 

    See this link for example

    3. Remove the service1 on WebHttpBinding. Leave you Android service as is.

    4. So now, android client makes a call to save to DB. DB notifies your PushService with new record. Then push service makes a call to the client.

    /Srinivas

    Monday, October 6, 2014 8:29 AM