需要有关服务堆栈实施的帮助 [英] Need help on servicestack implementation

查看:50
本文介绍了需要有关服务堆栈实施的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 servicestack 实现面临一个问题,我发出了以下请求 url 来调用我的服务并实现了一个 perfmon 类 &性能服务类

I an facing issue with my servicestack implementation, i have make followings requests url to call my service and implemented one perfmon class & perfmonservice class

    [RestService("/perfmon/application/{appliationId}")]
    [RestService("/perfmon/application/{appliationId}/{countername}")]
    [RestService("/perfmon/user/{userId}")]
    [RestService("/perfmon/user/{userId}/{countername}")] 

现在,当我调用任何 URL 时,它会调用以下函数

Now when i will call any of the URL it would call following function

 public override object OnGet(Perfmon request)
        {                
                return base.OnGet(request);
        }

那么我如何在这里确定哪个 URL 进行了这个调用,天气服务堆栈提供了任何特定的方法来做到这一点,或者我需要通过检查属性来编写手动逻辑?

so how can i decide here that which URL made this call , weather servicestack provide any specific way to do this or i need to write manual logic by checking properties?

提前致谢

推荐答案

只需检查请求 DTO 即可查看填充了哪些字段,即

Just inspect the request DTO to see which fields are populated, i.e.

if (request.applicationId != null && request.countername != null) #2
if (request.userId != null && request.countername != null) #4
if (request.applicationId != null) #1
if (request.userid != null) #3

另请注意,用户也可以使用查询字符串填充请求 dto,即,如果他们通过以下方式给您打电话:

Also note that the user can populate the request dto with the querystring as well, i.e. if they called you with:

/perfmon/application/1/countername?userId=2

然后将填充所有字段.最后,您可以使用用于调用请求的绝对 URI 来检索有关请求的信息:

Then all fields will be populated. Lastly you can retrieve information about the Request with like the Absolute URI used to call the request with:

base.RequestContext.AbsoluteUri

最后,您可以通过以下方式获取 IHttpRequest 对象本身:

Finally you can get the IHttpRequest object itself with:

var httpReq = base.Request; //or with base.RequestContext.Get<IHttpRequest>();

这篇关于需要有关服务堆栈实施的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆