ResolveService from a MQ Service throws null

I have a service that is being hosted as a Windows Service and hook up to a Redis server being part of a Message Queue and works great…

I’ve now an API that, instead of passing the order through all steps in the MQ I need the answer right away, so I tried to synchronously call the MQ Services, but I’m getting a null exception with trying to resolve the service:

All I did was to reference the Service and Model projects and call ResolveService

Am I forgetting something obviously?

The MQ Service is as such:

public class GiftcardCreatorService : BaseService
{
    public object Any(GiftcardCreatorMessage message, bool onlyThisStep = false)
    {
        // ...
    }
}

public abstract class BaseService : ServiceStack.Service
{
    // ...
}

I can easily create a WebHost project to host the GiftcardCreatorService and use JsonServiceClient to call it, and I know it works fine as I use that in other places, but I was wondering if I could easily call and re-use that MQ step code…

What am I missing?

ServiceStack Services can only have a single parameter which is the Request DTO so you’ll need to remove the 2nd parameter in your Service.

Hi @mythz

That’s ok, but that will still give me the service as null

it’s the service variable that is null, not actually the call…

so this:

var service = ResolveService<GiftcardCreatorService>()

is null :frowning:

So you changed it to:

public class GiftcardCreatorService : BaseService
{
    public object Any(GiftcardCreatorMessage message)
    {
        // ...
    }
}

And you’re still getting null from ResolveService<GiftcardCreatorService>? Strange, it doesn’t sound like your Service is being registered, Is the Service in the same Assembly as your other Services in your AppHost?

public class AppHost : AppHostBase
{
    public AppHost()
        : base("Service Name", typeof(MessageQueue.Service.Services.AServiceType).Assembly) {}

}

If it’s not in the Assemblies registered in your AppHost it wont be registered.

Hi @mythz

I do register it in the AppHost but it still does not resolve it :frowning:

Maybe I’m forgetting something simple? I also assumed it would work out of the box …

forgot that first part …

with only one parameter in the service, all works lovely :smile:

Thank you so much…

1 Like