Q: servicestack Root route and custom xml serilization I am currently having 2 issues in service stack. I am currently trying to build a service to imitate an existing server software.  This requires a few things that i am having issues with.
This is using a self hosted servicestack instance and latest version


*

*I need to have service on "/" that takes no paramters.

*All my services need to return results using a customer XML serializer not the data contact one no matter what is in the accept header. (currently return html representation of DTO)


For issue 1 i have been using  [FallbackRoute("/")] which is working but then no matter what i do i can't get my custom serializer to be used.
For issue 2 i made a custom serializer using the dotnet xml serializer that will generate the output i need and registered it as a ContentTypeFilters.  I then manually set the response type header but this did not trigger my serializer. This is really starting to drive me nuts as i need to implement about 20 services and i can't even get the simple root service working let alone the rest of them.
Basically my XML is in a format the DataContract serializer can't handle and the url's and content must be an exact match for the existing system.

A: It looks like both issue 1 and issue 2 are really the same issue; Your custom serialiser isn't getting called. This is either an issue with registering your serialiser, returning the content type or both. Below shows how you should set it up. Using ServiceStack v4:
Register your custom serialiser:
In your AppHost Configure method you need to register your custom XML serialiser:
StreamSerializerDelegate serialize = (request, response, stream) => {
    // Replace with appropriate call to your serializer and write the output to stream
    var myCustomSerializer = new MyCustomSerializer(response);
    stream.write(myCustomerSerializer.getResult());
};

StreamDeserializerDelegate deserialize = (type, fromStream) => {
    // Implement if you expect to receive responses using your type
    throw new NotImplementedException(); 
};

// Register these methods to run if content type 'application/xml' is sent/received
ContentTypes.Register("application/xml", serialize, deserialize);

Set the return content type:
In your service you need to set the return content type, so the serialiser knows to run. You can do this either by adding an attribute on each method than needs to use this type, or if all your methods return this type you can configure it as the default.
Per method basis:
You can use the AddHeader attribute with the ContentType parameter. i.e:
public class TestService : Service
{
    [AddHeader(ContentType = "application/xml")]
    public TestResponse Get(RootRequest request)
    {
        return new TestResponse { Message = "Hello from root" };
    }
}

All methods return this type:
You can set the default content type in the AppHost Configure method. i.e:
public override void Configure(Funq.Container container)
{
    SetConfig(new HostConfig { 
        DebugMode = true,
        DefaultContentType = "application/xml"
    });
}

Fully working demo app
The demo is a self hosted console app, that takes a request to the root / or to /Test and returns a custom serialised response.
Hope this helps.
