Search code examples
c#web-servicesrestwcfapi-key

WCF Service FileNotFound exception after Key authorization implementation


I have written a WCF API. It runs (ran) just fine. Now that I need to open it up to public access I tried to implement API Key verification following the example of Ron Jacobs and the accompanying video on endpoint.tv

This basically just uses a list of GUIDs stored in an xml file that represent the valid API keys. The authorization request key is passed via query string and validated in a custom ServiceAuthorizationManager like this:

protected override bool CheckAccessCore(OperationContext operationContext)
{
    return IsValidAPIKey(operationContext);
}

public static bool IsValidAPIKey(OperationContext operationContext)
{
    string key = TvinQuery.GetAPIKey(operationContext);

    Guid apiKey;

    // Convert the string into a Guid and validate it
    if (Guid.TryParse(key, out apiKey) && TvinQuery.APIKeys.Contains(apiKey))
    {
        return true;
    }
    else
    {
        return false;
    }
}

TvinQuery.APIKeysis a simple List<string> containing the valid guids from the xml file.

The solution compiles, but when I publish it on my server and try to access the service there, I get a FileNotFound exception for file or assembly "WCFWebHttp" or one of its dependencies.

The cause for this is very obviously this part in the service behavior node of web.config:

<serviceAuthorization serviceAuthorizationManagerType="WCFWebHttp.APIKeyAuthorization, WCFWebHttp" />

Unfortunately, neither a search through my assemblies nor through my file system nor an internet search nor a nuget package search came up with an assembly of that name.

Event viewer and enabled tracing did not reveal any further information either.

What is it? How can I solve this error? Is there anything wrong or missing with the example? It worked just fine in the video and that was a live presentation. :-?


Solution

  • As from this picture:

    enter image description here

    at https://blogs.msdn.microsoft.com/rjacobs/2010/06/14/how-to-do-api-key-verification-for-rest-services-in-net-4/

    it looks like WCFWebHttp is an assembly implemented in the source code of the sample you've used (which I can't download right now to make sure because of server error).