First thing you should try do is find out what the internal Exception is, does the Response Body contain any error details?
Otherwise see if you can catch the Exception by registering a callback in IAppHost.ServiceExceptionHandlers or IAppHost.UncaughtExceptionHandlers.
Note HttpResult is a server-side wrapper object that lets you customize and add additional headers to the HTTP Response, it’s not the response itself and should never be used on the client, i.e. IReturn<IHttpResult>. If this API returns binary data it should be labelled as IReturn<byte[]> instead. As a rule you IReturn<T> should never contain an interface, it normally contains the DTO Response Type or raw data like IReturn<string> or IReturn<byte[]>.
I wired up an UncaughtExceptionHandler and found the following:
System.Net.ProtocolViolationException: Bytes to be written to the stream exceed the Content-Length bytes size specified.
at System.Net.HttpResponseStream.Write(Byte buffer, Int32 offset, Int32 size)
at ServiceStack.Formats.HtmlFormat.SerializeToStream(IRequest req, Object response, IResponse res)
at ServiceStack.Host.ContentTypes.SerializeToStream(IRequest req, Object response, Stream responseStream)
at ServiceStack.HttpResult.d__112.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.HttpResult.d__111.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.HttpResponseExtensionsInternal.d__2.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at ServiceStack.HttpResponseExtensionsInternal.d__7.MoveNext()
I figured this was due to the fact that I was setting a header value for Content-Length. However, when I comment out this line I still get the same exception.
Is there some way for me to manipulate the headers and return no body?
I’ve tracked down the issue to a HttpResult with null response which is resolved in this commit. This fix is available from v5.0.0 that’s now available on MyGet. Please note v5 changes before upgrading.
The way I’d handle a HEAD request is to use a separate method for the Service and write the HTTP Headers directly to the response. You’ll need to use the custom SetContentLength() API to set the Content-Length, e.g: