atevans
atevans

Reputation: 373

How to ensure message delivery to SOAP endpoint?

I'm consuming a notoriously unreliable SOAP web service in a c# MVC project. I have no control over that service. It will occasionally just stop responding for extended periods. Is there a simple way, from the client side, to continue to retry sending the message, at a set interval, until I receive a response back from the service?

I've looked at MSMQ and ws-reliability but, it appears to me, both options require some control over the web service. Is there anything out there to help me to do this from the client side?

Upvotes: 0

Views: 339

Answers (2)

As you probably already figured out, your problem is a huge problem for many. Look up "idempotent" and "webservice". Idempotency means a lot more than just being able to ensure a request/response, but a search will give you plenty of good stuff to read.

If "stop responding for extended periods" means seconds while seldomly called upon, DarkWanderer showed a pretty brute force solution to such a problem.

But if you have many calls, sleeping may eat up your working threads, so then you simply have to rely on some kind of queue.

If your calls are non-transactional and non-critical, you could surely code your own queing mechanism. While this may seem easy, it may still require threading, complex callbacks, logging, active error handling and what not. Many poor souls have reported that what started as a simple solution was turned into a maintainance nightmare.

And now I see that one of your requirements is that it must survive an app-pool recycling. Then we are in the last category of critical (and maybe transactional) queing.

Why I would recommend MSMQ from the very start. It handles all your problems and the api is in .net and really good nowadays. Yes, it will add complexity to your overall solution, but that stems from your problem domain.

Upvotes: 3

DarkWanderer
DarkWanderer

Reputation: 8866

while (true) {
    try {
        var response = webServiceClient.CallMethod();
        if (response.Successful())
            break;
        Sleep(retryInterval);
    } catch {}
}

And that means, you just need to keep calling the web-service, no message queue or something is required. Does that answer your question?

Upvotes: 1

Related Questions