我的服务模式:
[Route("/customer/{CustomerId}/creditcardtoken/{CanLookup}", "POST")]
public class CreditCardToken : IReturn<CreditCardTokenResponse>
{
[ApiMember(ParameterType = "path", DataType = "string", IsRequired = true, Verb = "POST")]
public string CustomerId { get; set; }
[ApiMember(ParameterType = "path", DataType = "boolean", IsRequired = true, Verb = "POST")]
public bool CanLookup { get; set; }
[ApiMember(ParameterType = "body", DataType = "CreditCard", IsRequired = true, Verb = "POST")]
public CreditCard CreditCard { get; set; }
}
public class CreditCard
{
public short CreditCardTypeId { get; set; }
public string NameOnCard { get; set; }
public string CardNumber { get; set; }
public string Expiration { get; set; }
public string PostalCode { get; set; }
}
服务接口没有任何内容(我在return null上设置了一个断点):
public class CreditCardTokenService : Service
{
public CreditCardTokenResponse Post(CreditCardToken request)
{
return null;
}
}
在撰写此问题时(针对.Net 4.6.2),使用最新版本的servicestack。
当我在Swagger-UI中填充字段时,CreditCard对象不会通过,它只是null。不确定我缺少什么,CustomerId和CanLookup会通过。我尝试在CreditCard类上设置DataContract / DataMember。
最佳答案
您的请求DTO与声明的Swagger模式不匹配,CreditCard
不是主体,它只是具有复杂类型值的参数。整个CreditCardToken
请求DTO都应作为HTTP POST请求的JSON正文进行POST,而此定义仅发布CreditCard
JSON正文。其他参数之所以通过,是因为它们是在请求的路径信息上发送的,也就是说,它们不是在正文中发送的。
关于c# - Servicestack对象参数未通过Swagger-UI传递给服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40684031/