首页 > 解决方案 > Servicestack Gateway.Send 不适用于 POST

问题描述

我有这个服务方法

  public async Task Post(DeviceEndpointInsertTemp request)
        {
            //Some AYNC Code
         }

我这样称呼它

          var model = new DeviceEndpointInsertTemp() {DeviceNumber = deviceID, IOEndpointList = list, EventGridPostDateTime = postTime};
                var task = Gateway.SendAsync(model);
                await task; //wait for response

我收到这个错误

{"Could not find method named Put(DeviceEndpointInsertTemp) or Any(DeviceEndpointInsertTemp) on Service IntegrationService"}

直到我将 POST 更改为 ANY

public async Task ANY(DeviceEndpointInsertTemp request)
    {
        //Some AYNC Code
     }

你知道为什么吗?

标签: servicestack

解决方案


这在Service Gateway Docs中有解释:

不带注释的裸请求 DTO 作为POST发送,但使用HTTP 动词接口标记注释请求 DTO 也支持替代动词,其中包含IGet,IPut等的请求 DTO 使用类型化动词 API 发送,例如:

[Route("/customers/{Id}")]
public class GetCustomer : IGet, IReturn<Customer>
{
    public int Id { get; set ;}
}

因此,如果您想发送服务网关来发送PUT请求,您的请求 DTO 需要实现适当的HTTP 动词接口标记,例如:

public class DeviceEndpointInsertTemp : IPut, IReturn<TheResponse>
{
  //...
}

推荐阅读