tags:

views:

156

answers:

1

Hello,

I have a asp.net web application to call a function in WCF service to send SMS message. After sending a message, the WCF service needs to keep checking a virtual inbox at SMS provider and notify my web application if there is any new reply. There may be more than one web app to use this service. What's a good way to implement this?

Currently I have a function in WCF service like this, it's a OneWay operation contract. I am thinking to configure the instance management as PerSession.

    public void Send(SMSMessage message)
    {
        bool startRetrieving = _smsContext.Send(message);

        //keep polling virtual inbox to retrieve replies until it's expired
        while (startRetrieving && DateTime.Now < message.ReplyExpiry)
        {
           //send a http request to check inbox
           //if there is any new reply, notify my web application by making 
           //a http request
           //Check the inbox every xxxx seconds.
           System.Threading.Thread.Sleep(xxxx);
        }

        //if it is expired, tell sender app that time to receiving reply is expired
    }
A: 

This is a situation in which the correlation pattern is a good fit.

http://www.eaipatterns.com/ramblings/09_correlation.html

The basic idea is that each call or client gets its own id, then when the answer is coming back, you can identify where the result should go due the the correlation id.

How you implement it will depend on how robust your service needs to be. If you use per session, and the machine restarts, and you loose your sessions, is this OK?

When we have a system where we must not loose information, we setup 2 services. One used to send the call in, and another that the service uses to send data back to the client. If anything goes down, everything will be sent correctly when the system is back up again.

Shiraz Bhaiji