0

I am attempting to implement the IAsyncService interface with ServiceStack 3.9.17.0.

Here is the code for my service definition:

public class TestService : IAsyncService<int>
{
    object IAsyncService<int>.ExecuteAsync(int request)
    {
        return "Yup that worked";
    }
}

And here is the code from my Global.asax.cs:

public class Global : System.Web.HttpApplication
{
    public class TestServiceAppHost : AppHostBase
    {
        public TestServiceAppHost() : base("Test Async Web Services", typeof(TestService).Assembly) { }

        public override void Configure(Funq.Container container)
        {
            Routes.Add<int>("/Test");   
        }
    }
}

When I run and go to the metadata page I see the other 2 services that exist in this project which just implement IService (removed to keep samples clean) but my IAsyncService doesn't display and if i try to hit it i get the following message:

<Int32Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
    <ResponseStatus>
        <ErrorCode>KeyNotFoundException</ErrorCode>
        <Message>The given key was not present in the dictionary.</Message>
        <StackTrace>
                at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
                at ServiceStack.WebHost.Endpoints.Utils.FilterAttributeCache.GetRequestFilterAttributes(Type requestDtoType) 
                at ServiceStack.WebHost.Endpoints.EndpointHost.ApplyRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes, Object requestDto) 
                at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)
         </StackTrace>
    </ResponseStatus>
</Int32Response>

Any and all help would be greatly appreciated.

EDIT:

I have update the code to look like this after a suggestion from mythz (thanks again for replying).

DTO and Service:

[Route("/test")]
public class TestDTO
{
    public int request { get; set; }
}

public class TestService : IAsyncService<TestDTO>
{
    object IAsyncService<TestDTO>.ExecuteAsync(TestDTO request)
    {
        return "Yup that worked";
    }
}

I left the Global.asax.cs the same except i changes the route to use the DTO and made the route lower case to match the attribute on the DTO. I am still having the same issue.

Edit #2: I upgraded to v3.9.71 and am still having the same issue.

1 Answers1

0

ServiceStack Services require a Request DTO, i.e. a concrete POCO class. You cannot use an int as a Request DTO. If you need to you can wrap it in a POCO class, e.g:

[Route("/test")]
public class Request 
{
    public int Int { get; set; }
}
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Hey mythz, Thanks for the reply however adding the DTO didn't change anything. I will update the OP to have the most recent set of code. – Adam Harris Mar 06 '15 at 17:27
  • @AdamHarris did you also remove the `Route.Add` from the Global.asax? you shouldn't have the route registered twice. Also v3.9.17 is really old, consider upgrading to the latest [ServiceStack v3](https://github.com/ServiceStackV3/ServiceStackV3). – mythz Mar 06 '15 at 17:40
  • I switched it to Route.Add. I know its a super old version but its the last free one and management isn't going to pay for a license *sigh*. As for registering the Route twice, should I just leave the attribute on the DTO and remove the one from Global.asax, vice-versa, or just leave both? – Adam Harris Mar 06 '15 at 17:42
  • @AdamHarris All v3 releases are BSD/free - v3.9.71 is the last free version, see the link in the above for install instructions. I'd only declare routes on the DTO as then they'd also be available on the client. – mythz Mar 06 '15 at 17:50
  • Hey @mythz, I'm going to try updating ServiceStack and see if that helps. Thanks for pointing that out. – Adam Harris Mar 06 '15 at 18:08
  • It isn't working :( I updated to 3.9.71 and now im getting another about the route not being found. If i switch to just using IService everything works great but as soon as i change it to IAsyncService it tells me the route wasn't found and the test service doesn't show on the metadata page. – Adam Harris Mar 06 '15 at 19:54
  • @AdamHarris Just use `IService` or even better the `Service` convenience base class. `IAsyncService` is for the `/oneway/` [pre-defined routes](https://github.com/ServiceStackV3/ServiceStackV3/wiki/Routing#pre-defined-routes). – mythz Mar 06 '15 at 20:07