title: oAuth 2.0 and C# WCF Service
body: <p>I want to put some security in my C# WCF Rest Service and I was following this tutorial:
  <a href="http://www.codeproject.com/Tips/372422/Secure-WCF-RESTful-service-using-OAUTH" rel="nofollow">http://www.codeproject.com/Tips/372422/Secure-WCF-RESTful-service-using-OAUTH</a></p>
  
  <p>How can I upgrade these informations to use oAuth 2.0?
  I downloaded the DotNetOpenAuth and installed it to my simple project.</p>
  
  <p>This is my <strong>IRestService.cs</strong>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.ServiceModel.Web;
  using System.Text;
  
  namespace WCFoAuth2
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the      interface name "IRestService" in both code and config file together.
      [ServiceContract]
      public interface IRestService
      {
          [OperationContract]
           [WebInvoke(Method="GET",     ResponseFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="xml/    {id}")]
          string DoWork(string id);
      }
  }
  </code></pre>
  
  <p>And my <strong>RestService.svc</strong>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace WCFoAuth2
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestService" in code, svc and config file together.
      // NOTE: In order to launch WCF Test Client for testing this service, please select RestService.svc or RestService.svc.cs at the Solution Explorer and start debugging.
      public class RestService : IRestService
      {
          public string DoWork(string id)
          {
              return id;
          }
      }
  }
  </code></pre>
  
  <p>And the <strong>Web.config</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;appSettings/&gt;
    &lt;connectionStrings/&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0"/&gt;
      &lt;authentication mode="Windows"/&gt;
      &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="WCFoAuth2.Service1Behavior" name="WCFoAuth2.Service1"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="WCFoAuth2.IService1" behaviorConfiguration="web"&gt;
            &lt;identity&gt;
              &lt;dns value="localhost"/&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
        &lt;service behaviorConfiguration="WCFoAuth2.RestServiceBehavior" name="WCFoAuth2.RestService"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="WCFoAuth2.IRestService" behaviorConfiguration="web"&gt;
            &lt;identity&gt;
              &lt;dns value="localhost"/&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="WCFoAuth2.Service1Behavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
          &lt;behavior name="WCFoAuth2.RestServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="web"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Tks.</p>