找不到请求的处理程序

找不到请求的处理程序

本文介绍了ServiceStack:找不到请求的处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了三个路由.前两个工作正常,但最后一个返回主题错误.

I have three routes defined. First two work fine but the last one returns error in the subject.

    Routes.Add<FeeInstructionsList>("/policies/{clientPolicyId}/feeinstructions", "GET");
    Routes.Add<FeeInstructionsEdit>("/policies/{clientPolicyId}/feeinstructions/{feetype}", "GET");
    Routes.Add<List<FeeInstructionEditInfo>>("/policies{clientPolicyId}/feeinstructions", "POST");

当我将第三条路线称为/feeinstructions"时,它工作正常,但是当我添加上述路线时,它不起作用.

When I had third route as just "/feeinstructions", it worked fine, but when I added route as above it does not work.

FeeInstructionEditInfo 没有名为clientPolicyId"的成员.这可能是一个原因.如果是这样,我如何将它传递给服务而不需要修改我的 dto.它可以是这样的服务操作的附加参数吗?我不知道这是可能的,因为 ss 是每个请求一个 dto,但也许有办法?

FeeInstructionEditInfo does not have memeber called "clientPolicyId". Could that be a reason. If so, how do I pass it to service without requiring to modify my dto. Can it be additional parameter on the service operation like this. I don't this it is possible as ss is one dto per request, but maybe there is a way?

public List<FeeInstructionEditInfo> Post(int clientPolicyId, List<FeeInstructionEditInfo> request)

目前这个方法声明为

public List<FeeInstructionEditInfo> Post(List<FeeInstructionEditInfo> request)

这是正在发送的请求

> POST http://localhost:12543/api/policies/680455600/feeinstructions/
> HTTP/1.1 Content-Type: application/json Accept-Language: en-US
> Referer: http://localhost:12543/ClientBin/SR.SRUnite.ShellUI.xap
> Content-Length: 1408 Accept-Encoding: identity Accept:
> application/json User-Agent: Mozilla/5.0 (compatible; MSIE 9.0;
> Windows NT 6.1; WOW64; Trident/5.0; BOIE9;ENUS) Host: localhost:12543
> Connection: Keep-Alive Pragma: no-cache

这些是我原来的dtos,这些没变

These are my original dtos, and these have not changed

 [Route("/policies/{clientPolicyId}/feeinstructions/{feetype}","GET")]
 public class FeeInstructionsEdit
 {
     public int ClientPolicyId { get; set; }
     public string FeeType { get; set; }
 }

 public class FeeInstructionsEditResponse
 {
     public List<KeyValuePair> Instructions { get; set; }
     public List<KeyValuePair> Contacts { get; set; }
     public List<FeeInstructionEditInfo> FeeInstructions { get; set; }
 }

public partial class FeeInstructionEditInfo
{
    public int FeeInstructionId { get; set; }

    public string FeeTypeCode { get; set; }
    public string FeeTypeDescription { get; set; }
    public string FeeTypeGroupCode { get; set; }

    public string ProductName { get; set; }
    public string InsuredType { get; set; }
    public string Demographic { get; set; }
    public string Instruction { get; set; }
    public string Contact { get; set; }
    public decimal? FeeAmount { get; set; }
}

我会将 FeeInstructionEditInfo 列表发布到/clientPolicies/342434/feeinstructions 并且它不起作用,但发布到/feeinstructions 会.

I would post list of FeeInstructionEditInfo to /clientPolicies/342434/feeinstructions and it would not work, but posting to /feeinstructions would.

我现在使用这对 dto 发帖.

I now post using this pair of dto's.

 [Route("feeinstructions","POST")]
 public class FeeInstructionsSave
 {
     public int ClientPolicyId { get; set; }
     public List<FeeInstructionEditInfo> FeeInstructions { get; set; }
 }

 public class FeeInstructionsSaveResponse : IHasResponseStatus
 {
      public ResponseStatus ResponseStatus { get; set; }
 }

推荐答案

A 基本概念ServiceStack中是每项服务 需要使用请求 DTO 调用.可以使用 PathInfo、QueryString 和 Request Body 的任意组合填充此请求 DTO.

A fundamental concept in ServiceStack is that every service needs to be called with a Request DTO. This Request DTO can be populated with any combination of PathInfo, QueryString and Request Body.

这意味着如果你想传入一个集合,你需要让你的请求 DTO 继承它,例如:

This means if you wanted to pass in a collection you would need to have your Request DTO inherit from it, e.g:

[Route("/policies/{clientPolicyId}/feeinstructions", "POST")]
public class EditFeeInstructions : List<FeeInstructionEditInfo>
{
}

现在一切正常:

public List<FeeInstructionEditInfo> Post(EditFeeInstructions request)
{
   ...
}

对于空请求,您的服务将如下所示:

For an Empty Request your service would look like:

public class EmptyRequest {}

public object Post(EmptyRequest request)
{
   ...
}

即使您想自己手动处理请求,您仍然会需要提供一个请求 DTO 来表明您的意图,例如:

Even if you want to process the request manually yourself, you would still need to provide a Request DTO signalling your intent, e.g:

public class Hello : IRequiresRequestStream
{
    //The raw Http Request Input Stream gets injected here
    public Stream RequestStream { get; set; }
}

这篇关于ServiceStack:找不到请求的处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:54