简体   繁体   中英

Return 403 Error code from WCF service

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 ie forbidden.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM