1

I have a pretty basic RESTful WCF service in C# as follows.

public SchoolList[] GetSchoolList(string authenticationToken, string term, string stateID, string schoolTypes)
{
    if (!TokenAuthenticator.Authenticate(authenticationToken, out marketPlaceIdInner))
    {

        //throw new ApplicationException(Constants.InvalidAuth); //**line 1**
    }

    try
    {
        SchoolList[] returnedschoolList = schoolManagementCacheServiceClient.GetSchoolSuggestions(term, schoolTypes, stateID).ToArray<SchoolList>();
        return returnedschoolList;
    }
    finally
    {
        schoolManagementCacheServiceClient.Close();
    }
}

It is functioning well, what I want to achieve is when the control reaches line 1 I want to return a simple error string and HTTP Status code to be 403 i.e. forbidden.

How can I achieve it in minimal code? I have referred other code samples and that are too big and bit complex.

MaxRecursion
  • 4,773
  • 12
  • 42
  • 76
  • 1
    Have you seen http://stackoverflow.com/questions/5314625/causing-http-error-status-to-be-returned-in-wcf ? – lc. Dec 30 '13 at 12:33

1 Answers1

1

Have a look at this class http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.aspx

And this post: How can I return a custom HTTP status code from a WCF REST method?

Community
  • 1
  • 1
Jocke
  • 2,189
  • 1
  • 16
  • 24