Creating a Service URL in ServiceStack

How do I create a URL for a specific service defined in ServiceStack?

I want to include full or relative URLs in other endpoints as part of the DTO response. RestServiceBasecontains RequestContext.AbsoluteUri, but it depends entirely on the request.

+5
source share
1 answer

Reverse routing

The Reverse Routing section on the wiki shows how to use extension methods in a programmed DTO request to generate relative and absolute URIs:

[Route] ( Fluent API), URI, DTO, URL- - ServiceStack, .NET Service Clients ToUrl(HttpMethod) ToAbsoluteUri(HttpMethod), :

[Route("/reqstars/search", "GET")]
[Route("/reqstars/aged/{Age}")]
public class SearchReqstars : IReturn<ReqstarsResponse>
{
    public int? Age { get; set; }
}

var relativeUrl = new SearchReqstars { Age = 20 }.ToGetUrl();
var absoluteUrl = new SearchReqstars { Age = 20 }.ToAbsoluteUri();

relativeUrl.Print(); //=  /reqstars/aged/20
absoluteUrl.Print(); //=  http://www.myhost.com/reqstars/aged/20

Email Contacts HTML- Razor .

new RequestDto().ToPostUrl();
new RequestDto().ToPutUrl();
new RequestDto().ToDeleteUrl();
new RequestDto().ToOneWayUrl();
new RequestDto().ToReplyUrl();

Http

httpRequest :

var httpReq = base.RequestContext.Get<IHttpRequest>();

ASP.NET( HttpListener) :

var aspNetReq = httpReq.OriginalRequest;

, .

+4
source

All Articles