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.
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?
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.