0

I have a winform application and a wcf service. My intention is, when my winform application sends a request message to wcf service, the service has to store the details of the client request and after sometime, wcf will return a call back to the winform [client] application.

Suppose that there will be 10 such clients that sends a request to this wcf service and after 5 minutes the service will send a call back message to each client by sending a "hi" message.

My service implementation is like this.

  [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = 
       typeof(IServiceCallBacks))]
public interface IService
   {
          [OperationContract]
          void Connect(User user);
   }

And my call back method is as shown below

  public interface IServiceCallBacks
    {

    [OperationContract(IsOneWay = true)]
    void ContactsUpdated(List<Contact> updatedContacts);
    } 

And here is the implementation

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IService
{
    List<User> users = new List<User>();

    public Service()
    {

    }

    public void Connect(User user)
    {
        users.Add(user);
    }

Is this correct way ? How I can send a notification to each client from the service ?

Kuttan
  • 107
  • 4

1 Answers1

0

The problem with call-back contracts is that the connection needs to be open. A callback of "5 minutes" might fail because depending on the transport type the connection may have been closed prior due to inactivity.

If you run into problems, you might want to consider not using WCF "callbacks" at all and just treat the "client" as another service and have the "server" open up a connection to the "client" and invoke it. That would get around any such inactivity issue. The only issue is that of firewalls so you may need to be mindful of WCF transport choices and firewall ports.

  • thanks for the reply. if u dont mind could you please explain "just treat the client as anther service" with an example. – Kuttan Apr 15 '19 at 06:24