The header image for the 'WCF Service aborted by the server' post, sorry the platform doesn't allow alt text on headers

WCF Service aborted by the server

An error occurred while receiving the HTTP response to http://localhost:12345/SomeService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

This evening I spent more time than I would care to admit working on a problem in a WCF Service I am building. The service has been working well for a number of weeks whilst it has all its functions ironed out; suddenly today after adding in one of those functions it stopped working in debug. I blame tiredness and a busy day in the office for me not realising the error faster, but for those who like me get tired here is the cause of the above error (or at least this version of the error).

[DataContract]
public enum LoginResultFlag {
    [EnumMember]
    Success = 100,

    [EnumMember]
    Failure = 200,

    [EnumMember]
    PasswordChangeRequired = 300,

    [EnumMember]
    AccountLocked = 400,

    [EnumMember]
    RequiresChallenge = 500,

    [EnumMember]
    SetupChallengeResponse = 600
}

Can you see the problem; it took me a little while of trial end error before I spotted it the moment I looked at the enum. Enums cannot be null, at their most basic they are integers and take the value 0. If you specify integer values as I have done here without adding a zero value then it cannot be serialized/deserialized through the web service boundary. All I had to do was add the following to the enum:


[EnumMember]
NotSet = 0

Problem solved!

The header image on this post was provided by Maria Freyenbacher on unsplash.com. Thank you Maria!

About James Chorlton

I am a software developer from the South-West of England; I mostly work in .NET (c#) creating desktop, web, service, and backend software for the Legal and Health markets.

Comments