Trigger callback from REST? RRS feed

  • Question

  • I have a WCF service set up that allow for WPF clients to register to a callback. So basically those WPF clients will subscribe to the service and wait for a callback to give them a command. I'm not sure if this is possible but I want to be able to trigger the callback to be sent to the WPF clients from a RESTful service using android. Here is a really bad illustration that hopefully will help illustrate what I'm trying to do. I'm new with WCF services so I apologize if my terminology is off. Any help to accomplish this, i would really appreciate. I know i can do polling with a database, but I'd like to avoid that if possible. Thanks.

    Wednesday, August 8, 2012 6:41 PM

All replies

  • Hi,

    First you should create a WCF Restful Service for your Android Client to post information to the WCF Service.

    We need to use webHttpBinding to do the job.

    Then for communicating between WCF and WPF Client , you need to use Duplex Servide.

    If there is any issue encounter ,please feel free to post your problem to this forum.

    • Edited by Otomii Lu Thursday, August 9, 2012 8:13 AM
    • Proposed as answer by Shashank Chaturvedee Thursday, August 9, 2012 9:04 AM
    • Unproposed as answer by heyheyyeah Thursday, August 9, 2012 2:52 PM
    Thursday, August 9, 2012 6:49 AM
  • Thanks for your response. That's exactly the point where I am now. But I am unsure how to get the interface that uses webHttpBinding to call the method in the Callback to get the message sent to the WPF client. Here is the interface that would interact with WPF:

    <ServiceContract(SessionMode:=SessionMode.Required, CallbackContract:=GetType(IServiceCallback))>
    Public Interface IService
        Sub GetClientCount()
        Sub RegisterClient(ByVal id As Guid)
        Sub UnRegisterClient(ByVal id As Guid)
    End Interface
    Public Interface IServiceCallback
        Sub SendCount(ByVal count As Int32)
    End Interface

    Here is the method i want the Restful Service to be able to call but I'm just not sure how to do so with webHttpBinding because of course the code I posted above uses wsDualHttpBinding.

        Private clients As New Dictionary(Of Client, IServiceCallback)()

    'called by clients to get count Public Sub GetClientCount() Implements IService.GetClientCount Dim query = ( _ From c In clients _ Select c.Value).ToList() Dim action As Action(Of IServiceCallback) = Function(Callback) GetCount(Callback) query.ForEach(action) End Sub

    EDIT: To add more detail, the GetClientCount() is in the Service class which is the class that has a dictionary of the WPF clients that have been connected to service. Then I have another interface that uses wsDualHttpBinding that i call IAndroid. This service looks like this:

        <WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Json, UriTemplate:="/SendToWPFClients/{data}")>
        Function SendToClients(ByVal data As String) As System.IO.Stream
    Public Class Android
        Implements IAndroid
        Public Function SendToClients(data As String) As System.IO.Stream Implements IAndroid.SendToClients
            Dim s As New Service
            Return Nothing
        End Function
    End Class
    but when I call the GetClientCount() in the Service, it also is 0. So I know that I'm creating a New instance of Service and that why its happening, but i thought that setting the InstanceContextMode:=InstanceContextMode.Single in my class called "Service" would force the service to only create one instance of the class. So i guess specifically, I just need to call Service.GetClientCount() from my Android Class.

    • Edited by heyheyyeah Thursday, August 9, 2012 2:36 PM
    Thursday, August 9, 2012 1:24 PM
  • Hi bflosabre91,

    Sorry for coming back later.

    Please refer to the link below:

    Please download the samples and refer to the dict:WCF\Scenario\DesignPatterns\ListBasedPublishSubscribe

    You find the project have provide a sample for Subscribing the information from service-side.

    Monday, August 13, 2012 3:36 AM
  • Thanks for the response. My service is able to subscribe to but I'm having issues getting REST to work with the Subscribing clients. After the clients subscribe to the service I have a method called SendToClients() which just sends a string value to all subscribing clients. This works fine if it is initiated from any one of the clients but I want that method to be called from REST.

    I have one interface set up for webHttpBinding called IAndroid which is the RESTful service that my android client connects to. I have another interface set up for wsDualHttpBinding called IService and that service is where my WPF clients connect to subscribe. That is also where the method SendToClients() is located that just sends a string message to the WPF clients that are subscribed to the service. But I would like to be able to execute SendToClients() from my RESTful class. So on android, i could go to and then "hiWPF" would be send to each of the clients.

    Monday, August 13, 2012 1:53 PM