1

Hello ServiceStack aficionados!

I would like to host static XML files through the ServiceStack service; however, I can't seem to get the configuration right and only receive 404 errors. Feels like I tried all sorts of path/url combinations.

Can the WebHostPhysicalPath be defined as a relative path? Is there another setting that must be enabled? I was concerned that maybe the XML extension is conflicting with the format conversion stuff.

Also, can I host Razor cshtml files this way too?

Any comments on this approach?

thanks!

Community
  • 1
  • 1
sirthomas
  • 12,576
  • 1
  • 13
  • 15

1 Answers1

1

You can return a static file from a service like so:

[Route("/myFile/")]
public class GetMyFile
{
}

public class HelloService : Service
{
    public HttpResult Any(GetMyFile request)
    {
        return new HttpResult(new FileInfo("~/myfile.xml"), asAttachment:true) { ContentType = "text/xml" };
    }
} 

As for razor: http://razor.servicestack.net/

Eric W.
  • 7,148
  • 3
  • 20
  • 27
  • FYI Adding 'xml' isn't needed as its [already pre-configured](https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/WebHost.Endpoints/EndpointHostConfig.cs#L87). – mythz Sep 15 '13 at 04:12
  • I thought so, I just couldn't remember. Since you're here, thanks for the only framework keeping me on .NET. – Eric W. Sep 15 '13 at 04:36
  • Thx, SS is keeping me on .NET as well - not sure if that's a good thing yet :) – mythz Sep 15 '13 at 04:46
  • I didn't want the files to be per-Service, so in the end I went with this linked approach, but haven't gotten to hosting my own razor just yet. SS is awesome on .net, @mythz please stick with it! [link] (http://stackoverflow.com/questions/15744093/servicestack-serving-static-files-from-a-directory-when-present) http://stackoverflow.com/questions/15744093/servicestack-serving-static-files-from-a-directory-when-present – sirthomas Nov 29 '13 at 12:44
  • Reflected on this a bit more and added your solution (@EricW.) to give it a whirl too - other than digging to find the namespace for HttpResult (servicestack.common.web for others on pre-4.0) and removing the ~, it worked cleanly and will explore this further. Thanks! – sirthomas Nov 29 '13 at 13:22