Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7617675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:12:32+00:00 2026-05-31T03:12:32+00:00

I have constructed a simple Rest service using ServiceStack (which is brilliant), that returns

  • 0

I have constructed a simple Rest service using ServiceStack (which is brilliant), that returns a list of key value pairs.

My service looks like this:

 public class ServiceListAll : RestServiceBase<ListAllResponse>
{
    public override object OnGet(ListAllResponse request)
    {          
        APIClient c = VenueServiceHelper.CheckAndGetClient(request.APIKey, VenueServiceHelper.Methods.ListDestinations);

        if (c == null)
        {
            return null;
        }
        else
        {
            if ((RequestContext.AbsoluteUri.Contains("counties")))
            {
                return General.GetListOfCounties();
            }

            else if ((RequestContext.AbsoluteUri.Contains("destinations")))
            {
                return General.GetListOfDestinations();
            }

            else
            {
                return null;
            }
        }
    }
}

my response looks like this:

    public class ListAllResponse
{
    public string County { get; set; }
    public string Destination { get; set; }
    public string APIKey { get; set; }     
}

and I have mapped the rest URL as follows:

.Add<ListAllResponse>("/destinations")
.Add<ListAllResponse>("/counties")

when calling the service

http://localhost:5000/counties/?apikey=xxx&format=xml

I receive this exception (a breakpoint in the first line of the service is not hit):

NullReferenceException

Object reference not set to an instance of an object.

at ServiceStack.Text.XmlSerializer.SerializeToStream(Object obj, Stream stream) at ServiceStack.Common.Web.HttpResponseFilter.<GetStreamSerializer>b_3(IRequestContext r, Object o, Stream s) at ServiceStack.Common.Web.HttpResponseFilter.<>c_DisplayClass1.<GetResponseSerializer>b__0(IRequestContext httpReq, Object dto, IHttpResponse httpRes) at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)

The exception is thrown regardless of whether I include any parameters in call or not. I have also created a number of other services along the same lines in the same project which work fine. Can anyone point me in the right direction as to what this means?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:12:34+00:00Added an answer on May 31, 2026 at 3:12 am

    Your web service design is a little backwards, Your Request DTO should go on RestServiceBase<TRequest> not your response. And if you’re creating a REST-ful service I recommend the name (i.e. Request DTO) of your service to be a noun, e.g. in this case maybe Codes.

    Also I recommend having and using the same strong-typed Response for your service with the name following the convention of ‘{RequestDto}Response’, e.g. CodesResponse.

    Finally return an empty response instead of null so clients need only handle an empty result set not a null response.

    Here’s how I would re-write your service:

     [RestService("/codes/{Type}")]
     public class Codes {
          public string APIKey { get; set; }     
          public string Type { get; set; }
     }
    
     public class CodesResponse {
          public CodesResponse() {
               Results = new List<string>();
          }
    
          public List<string> Results { get; set; }
     }
    
     public class CodesService : RestServiceBase<Codes>
     {
          public override object OnGet(Codes request)
          {          
               APIClient c = VenueServiceHelper.CheckAndGetClient(request.APIKey, 
                  VenueServiceHelper.Methods.ListDestinations);
    
               var response = new CodesResponse();
               if (c == null) return response;
    
               if (request.Type == "counties") 
                    response.Results = General.GetListOfCounties();
               else if (request.Type == "destinations") 
                    response.Results = General.GetListOfDestinations();
    
               return response; 
         }
     }
    

    You can either use the [RestService] attribute or the following route (which does the same thing):

    Routes.Add<Codes>("/codes/{Type}");
    

    Which will allow you to call the service like so:

    http://localhost:5000/codes/counties?apikey=xxx&format=xml
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose, I have a lot of classes, which are constructed using Java reflection (for
I have a site that has a simple API which can be used via
I have a list that every bock is constructed like below. Some of the
My problem in fairly simple. I have a login system constructed using php, mysql
Python Decimal doesn't support being constructed from float; it expects that you have to
Greetings, I have a particular object which can be constructed from a file, as
I'm using Jersey to create a REST web service for a server component. The
I have a data.frame in R which has been constructed off the Example 1-3
I have a fairly large chunk of code that produces/returns an arraylist of search
I have created a WCF service which does not use the app.config to configure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.