我正在使用Swagger UI(版本:3.9.59)。 我编写了一个名为GetProduct的ServiceStack合约。代码如下。
[Route("/products/{Id}",
Verbs="GET",
Notes = "Gets the product by id",
Summary = "Object that doesn't need to be created directly")]
[Api("Get the product by id")]
[ApiResponse(HttpStatusCode.NotFound, "No products have been found in the repository")]
public class GetProduct
{
[ApiMember(AllowMultiple = false,
DataType = "int",
Description = "Represents the ID passed in the URI",
IsRequired = false,
Name = "Id",
ParameterType = "int",
Verb = "GET")]
[ApiAllowableValues("family", typeof(int))] //Enum
public int Id { get; set; }
}
在我通过谷歌浏览器运行Swagger UI之后,我看到了图1.我在图1中的文本框中输入了一些产品ID,例如1,然后我点击了“试一试!”按钮。
但是我得到了RequestBindingException。详细信息如下。
返回的请求网址'http://localhost:50712/products/ {Id}?api_key = special-key'。
返回的响应正文
{
"ResponseStatus": {
"ErrorCode": "RequestBindingException",
"Message": "Unable to bind request",
"StackTrace": " in ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)\r\n in ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)"
}
}
返回的响应代码 400。
返回的响应标头是
Date: Tue, 08 Dec 2015 09:44:13 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: application/json; charset=utf-8
Cache-Control: private
X-SourceFiles: =?UTF-8?B?RDpcWWFuZ0xpXOWFrOWPuOi1hOaWmVxQcm9qZWN0c1xTZXJ2aWNlU3RhY2tc5a2m5Lmg6LWE5paZXOS5puexjea6kOeggVxTZXJ2aWNlU3RhY2sgU3VjY2luY3RseVzop6Pljovku7bvvIjlj6/kv67mlLnvvIlcQ2hhcHRlcjEyIC0gRG9jdW1lbnRpbmcgV2ViIFNlcnZpY2VzXFNlcnZpY2VTdGFjay5TdWNjaW5jdGx5Lkhvc3RccHJvZHVjdHNce0lkfQ==?=
Content-Length: 346
Google Chrome返回了以下信息。
图:
如何解决上述问题?