endpoint.tv - How to Do API Key Verification with a WCF WebHttp (REST) Service
- Posted: Jun 17, 2010 at 7:00 AM
- 20,531 Views
- 4 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- High Quality WMV (PC, Xbox, MCE)
- MP3 (Audio only)
- MP4 (iPod, Zune HD)
In .NET 3.5, we created the REST Starter Kit as a way to get you up and running with RESTful services. Now that .NET 4 is out, people are asking how to do things like API Key Verification in .NET 4. In this episode, I'll walk you through a sample.
For more info
- Try the Project Template from Visual Studio
- Download the sample code from Code Gallery
- Read about it on my blog
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Is there going to be a REST Starter Kit version for .NET 4??
Still working on the plan. Most of the server stuff ended up in .NET 4. The only part that we don't have is the HttpClient library (which is really cool). It totally works on .NET 4 if you just grab the source and build it.
How do we pass it in if we're using the WebReference ServiceClient object?
@Steve Scott: Thanks for your fine solution. I have changed it little so it can also be used with (OData) Service references. I also check the header of the request:
public string GetAPIKey(OperationContext operationContext)
{
var request = operationContext.RequestContext.RequestMessage;
var requestProp =
(HttpRequestMessageProperty)request.
Properties[HttpRequestMessageProperty.Name];
NameValueCollection queryParams =
HttpUtility.ParseQueryString(requestProp.QueryString);
string apiKey = queryParams[APIKEY];
if (apiKey == null)
{
apiKey = requestProp.Headers[APIKEY];
}
return apiKey;
}
and on the client, i pass the ApiKey in the header using the SendingRequest event:
service.SendingRequest += new
EventHandler<System.Data.Services.Client.SendingRequestEventArgs>
(service_SendingRequest);
static void service_SendingRequest(object sender,
System.Data.Services.Client.SendingRequestEventArgs e)
{
e.Request.Headers.Add("APIkey", "918704ec-4811-45b6-a169-16bae3df69a8");
}
See also:
http://adi.atosoriginblog.nl/2010/12/28/flexibel-apikey-gebruik-bij-wcf-data-services/
Remove this comment
Remove this thread
close