모든 examples 내가 본 것은 응답을 처리 할 필요가 없다는 것을 보여줍니다.
public Product GetProduct(int id)
{
Product item = repository.Get(id);
if (item == null)
{
var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("No product with ID = {0}", id)),
ReasonPhrase = "Product ID Not Found"
}
throw new HttpResponseException(resp);
}
return item;
}
HttpResponseException의 소스 코드를 보면, 그것이 그 값을 가진 속성 (HttpResponseMessage Response
)를 채우는이 표시되고, 폐기하는 것은 아마이 발생할 것 HttpResponseMessage 경우 ObjectDisposedException가 발생하거나 클라이언트에게 전달하는 데 실패 중 하나.
또한 SupressMessage가 소스 코드에 것을 알 수 있습니다 :
[SuppressMessage("Microsoft.Reliability",
"CA2000:Dispose objects before losing scope",
Justification = "Instance is disposed elsewhere")]
인스턴스가 (이 HttpResponseMesssage에 언급되지 않은, 그것은으로 IDisposable을 구현하지 않는) 다른 곳으로 배치된다.
이 문제를 해결하는 올바른 방법은 무엇입니까?
코드 변경이 필요하지 않습니다.
그것은 그들의 클래스 이런 식으로 구조 것이 흥미 롭다. 나는 문서에서 도움이되는 것을 찾을 수는 없지만 [this constructor] (http://msdn.microsoft.com/en-us/library/hh835324(v=11118).aspx)을 사용할 수는있다. 대신 상태 코드? –
"너무 빨리 처리되지 않습니까?" 너무 일찍, 정확히? – spender
@spender, 나는 응답이 클라이언트에 스트리밍되기 전에 폐기 될 것이라고 말하고있다. –