1

I have a simple service like this:

[Route("/Message/{Folder}", "GET")]
public class MessageList : IReturn<List<Message>>
{
    public string Folder { get; set; }
}

public class MessageListService : Service
{
    private readonly IDatabase _database;
    public MessageListService(IDatabase database)
    {
        _database = database;
    }

    public List<Message> Get(MessageList request)
    {
        return _database.Fetch<Message>(
        "EXEC GetMessage @@Folder=@1", request.Folder);
     }

I call it like this:

     http://localhost/Message/Inbox

Somehow, the service got hit twice: first the right request, then again with request.Folder undefined. The strange thing is, even the second call doesn't return any data, the framework always return the correct result from the first call. So I never noticed this until happened to run a SQL profiler.

I couldn't figure out exactly what causes the retry. I thought it might be data related because if I call Inbox through my razor UI, it doesn't repeat. If I call Archive, then it does. But if I call with random parameter like XYZ that returns no data, it also repeat the call.

However, if I call the service like this:

  http://localhost/Message/Inbox?format=json

then it always hit service twice, one valid and one without input parameter. But the Json result seems always correct. The second invalid call just hit database then disappeared.

Really need some help. Any idea what's going on?

Whoever
  • 1,295
  • 1
  • 14
  • 21
  • Narrow it down to 8 records. If these 8 returned from database, the service got hit a second time null parameter in the request. But couldn't pin point further. There are Html tags in these result, not sure if that matters. But what I couldn't understand is how can data result can cause the request/service to retry itself. – Whoever Oct 19 '13 at 22:45

1 Answers1

2

ServiceStack doesn't call itself, if a service is being called twice it's likely the client doing it. Use Fiddler or WebInspector to find out what's really going on. E.g If you're using an Ajax client then the browser might be issuing a separate OPTIONS request, in which case you can short-circuit all OPTIONS request with a Global Request filter.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • 1
    I thought by using format=json I already eliminated all my client code. Turned out a bookmark extension in my browser intercept certain combination in the page and ping back to server on its own. That was a day well wasted! Thank you so much for all your help. The framework is so amazing that I abandoned more than 6 months of work trying to switch, thus the pressure and all the stupidity ^_^ – Whoever Oct 19 '13 at 23:21
  • Ouch rewriting is always a risk and not much fun - hope it works out! – mythz Oct 19 '13 at 23:38