Search code examples
servicestackfiddler

Debugging self hosted service servicestack


I am checking servicestack example projects Is that possible to debug self hosted service?

namespace StarterTemplates.Common
{
    /// <summary>
    /// Define your ServiceStack web service request (i.e. the Request DTO).
    /// </summary>  
    [Description("ServiceStack's Hello World web service.")]
    [Route("/hello")]
    [Route("/hello/{Name*}")]
    public class Hello
    {       
        public string Name { get; set; }
    }

    /// <summary>
    /// Define your ServiceStack web service response (i.e. Response DTO).
    /// </summary>
    public class HelloResponse : IHasResponseStatus
    {       
        public string Result { get; set; }      
        public ResponseStatus ResponseStatus { get; set; }
    }

    /// <summary>
    /// Create your ServiceStack web service implementation.
    /// </summary>
    public class HelloService : ServiceBase<Hello>
    {
        protected override object Run(Hello request)
        {
            return new HelloResponse { Result = "Hello, " + request.Name };
        }
    }
}

Runs under port 32. From fiddler http://localhost:32/servicestack/xml/syncreply/Hello?Name=World but I get always 404 error. Any ideas ?

Other non self hosted examples run as charm.

Any idea


Solution

  • Self-hosted services aren't hosted under a /custompath, try instead:

    http://localhost:32/xml/syncreply/Hello?Name=World
    

    The example projects looks dated as the recommended way to create a service is to use ServiceStack's New API, e.g:

    public class HelloService : Service
    {
        public object Any(Hello request)
        {
            return new HelloResponse { Result = "Hello, " + request.Name };
        }
    }
    

    There are also new routing options which lets you access the same service with the shorter:

    http://localhost:32/xml/reply/Hello?Name=World
    

    And if you've got custom routes defined you can use different ways to ask for Content Negotiation, e.g:

    http://localhost:32/hello?Name=World&format=xml
    http://localhost:32/hello.xml?Name=World