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

  • Home
  • SEARCH
  • 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 7654869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:22:01+00:00 2026-05-31T12:22:01+00:00

We have a legacy server code that we want to abandon and develop new

  • 0

We have a legacy server code that we want to abandon and develop new one using ServiceStack. Existing clients are not written in .Net. We don’t plan to use .Net on the client side at all.

Data between client and server is being exchanged using XML and JSON – at the moment JSON is only used as a return format for the response (just for some of the services available). XML format was defined when the first version of the server solution was created couple of years ago. We don’t want to change it.

How do we use ServiceStack to build new RESTful webservices, that will serialize and deserialize data to a format that was designed in the past (please note, that clients will not be written in C#/.Net). We need to contol both: serialization & deserialization. Is that possible to use DTOs and still have control on how are these objects serialized / deserialized?

  • 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-31T12:22:03+00:00Added an answer on May 31, 2026 at 12:22 pm

    Adding custom logic via Request / Response Filters

    See Request and response filters to see how to add custom logic before and after your service is called. It’s best to add these filters via the Request / Response FilterAttributes as it allows you mark only the services that need these filters applied.

    The problem with the Request Filter is it happens after the deserialization into the request DTO which is too late to add custom de-serialization logic. To get around this you can register a custom Request binder in your AppHost with:

    base.RegisterRequestBinder<MyRequest>(httpReq => ... requestDto);
    

    This gives you access to the IHttpRequest object and lets you add the custom deserialization logic yourself. The other option is to tell ServiceStack to not attempt to deserialize the request itself and instead inject the HttpRequest InputStream so you can deserialize the request yourself:

    public class Hello : IRequiresRequestStream {
        Stream RequestStream { get; set; }
    }
    

    Both these examples are explained on ServiceStack’s Serialization and De-Serialization wiki page.

    Registering your own Custom Media Type

    Another option to be able to return strong-typed DTOs but change the output for certain requests can be done by adding a new custom media type as explained in the Northwind VCard Custom media type example, e.g:

    public static void Register(IAppHost appHost)
    {
        appHost.ContentTypeFilters.Register( "text/x-vcard", SerializeToStream,  DeserializeFromStream);
    }
    
    ...    
    
    public static void SerializeToStream(IRequestContext requestContext, object response, Stream stream)
    {
        var customerDetailsResponse = response as CustomerDetailsResponse;
        using (var sw = new StreamWriter(stream))
        {
            if (customerDetailsResponse != null)
            {
                WriteCustomer(sw, customerDetailsResponse.Customer);
            }
            var customers = response as CustomersResponse;
            if (customers != null)
            {
                customers.Customers.ForEach(x => WriteCustomer(sw, x));
            }
        }
    }
    

    This is a good option if you can mount the custom XML responses under a different Content Type, e.g. application/v-xml so it doesn’t conflict with the existing XML format/endpoint. Using the ContentType above your HTTP Client can call this custom implementation with ?format=v-xml or using the HTTP Header: Accept: application/v-xml.

    If you want to override the built-in XML ContentType you still can but I recommend falling back to the original XmlSerializer implementation for the SerializeStream and DeserializeStream methods if it’s not one of the legacy formats you have to support.

    By-pass ServiceStack and execute using your own Custom IHttpHandler

    Another option is to by-pass ServiceStack completely and instead process the request in your own custom IHttpRequest handler by registering it in ServiceStack’s config in your AppHost:

     SetConfig(new EndpointHostConfig { 
        RawHttpHandlers = {
          httpReq => return IsLegacyMatch(httpReq) ? new LegacyXmlHandler() : null 
        }
     });
    

    Returning non-null (i.e. any handler) by-passes ServiceStack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to start using guice in an existing application that has legacy code.
In one of my programs, I have to interface with some legacy code that
I have a legacy Windows server service and (spawned) application that works fine in
In a legacy database (SQL Server 2000), we have a clustered index that looks
I have legacy C# code and I am using Visual Studio 2008. I am
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
I have a legacy JSF application. Now that we want to add i18n support
Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web
Ok, so I've got some legacy code from another company that I have to
I have a lot of legacy code that is now a backend for a

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.