dotnet / dotnet/wcf

NRE when response has Content-Type but empty body

Open
#2,999 10 comments 1 reaction 1 assignee Claimed by @mconnew View on GitHub
Backlog bug
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

When a SOAP service returns no content but has a Content-Type set, WCF throws a NullReferenceException in HttpResponseMessageHelper. Leaving off Content-Type works fine.

**Example HTTP response that reproduces the issue**
```
HTTP/1.1 500
Content-Length: 0
Content-Type: text/xml; charset=UTF-8
Date: Thu, 05 Jul 2018 21:10:34 GMT
Connection: close
```

**Expected Result**
> System.ServiceModel.CommunicationException : The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."

**Actual Result**
> System.NullReferenceException : Object reference not set to an instance of an object.

The NRE happens due to inputStream being null in HttpResponseMessageHelper.DecodeBufferedMessageAsync when it attempts to dispose it in the finally block.

The root cause however looks to be in ValidateContentTypeAsync. It doesn't properly handle this situation. It returns true (last line in the method) if the content type has a value and content length is 0, when it should be returning false. Its return value is saved in a `hasContent` variable in ParseIncomingResponse, so it definitely looks like it should be returning false if there's no content.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.