Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF 4 REST service can't return a StatusDescription, only StatusCode
    primarykey
    data
    text
    <p>I'm currently migrating my WCF RESTful service from .NET 3.5 (Starter Kit) to .NET 4. I started my project using a WCF Rest service template from Visual Studio 2010. I had to figure out how to keep my authorization scheme (formely done with RequestInterceptor) using ServiceAuthorizationManager. After some work and researching I got it done. But now I have a collateral problem. My service used to feedback my client of any processing errors using HTTP status code and a brief description. I was using WebOperationContext at many points of my service method to describe to clients what went wrong, like this:</p> <pre><code>protected void returnCode(HttpStatusCode code, string description) { WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.StatusDescription = description; ctx.OutgoingResponse.StatusCode = code; } </code></pre> <p>But in WCF 4, only StatusCode works - StatusDescription silently fails. I can't figure out why. My only guess is that WebOperationContext doesn't work in this new WCF 4 scenario, and I should be using OperationContext instead, but that also doesn't work. The following method is used in my custom class extending ServiceAuthorizationManager, informing clients a request couldn't be access because auth digest was malformed:</p> <pre><code>private void GenerateBadDigestMessage(ref OperationContext operationContext) { Message reply = Message.CreateMessage(MessageVersion.None, null, null, new DataContractJsonSerializer(typeof(object))); HttpResponseMessageProperty hrp = new HttpResponseMessageProperty(); hrp.StatusCode = HttpStatusCode.Forbidden; hrp.StatusDescription = "bad digest"; reply.Properties[HttpResponseMessageProperty.Name] = hrp; operationContext.RequestContext.Reply(reply); operationContext.RequestContext = null; } </code></pre> <p>Even by using OperationContext direclty here (insted of WebOperationContext), StatusDescription doesn't work.</p> <p>What I'm missing here? Why such a small thing can break from .NET 3.5 to 4? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload