WCF WebHttp REST Entity Service

Demonstrates a REST Service built with WCF 4 that fully complies with HTTP specs for use of GET, PUT, POST, DELETE and includes unit tests to test compliance. Note: For the new WCF WebApi see WCF WebApi REST Entity Service ca·non·i·cal [ kə nónnik'l ] conforming to general pr

C# (181.8 KB)
5 Star
8,899 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • Example code test error on IISExpress
    1 Posts | Last post November 15, 2012
    • qjs
      I run the test project came with this Rest service on my win7\VS2010 ultimate. I see command window display the IISExpress started but got error:
      Failed	DeleteShouldBeIdempotent	CannonicalRESTWebApp.Tests	Class Initialization method CannonicalRESTWebApp.Tests.CannonicalWebApiTest.StartServers threw exception. System.InvalidOperationException: System.InvalidOperationException: Timeout trying to find window c:\Program Files (x86)\IIS Express\iisexpress.exe.	
      Can ou throw some light how to resolve this issue?
  • WCF webhttp vs. WebAPI
    2 Posts | Last post April 06, 2012
    • Hi Ron,
      I notice your note on the "new WCF WebAPI". Need a little help as I try to hack my way through the WCF/REST wilderness.
      What is the difference between WCF4 webHTTP and this "new WCF WebAPI"?
      Is the "new WCF WebAPI" the same as the WebAPI that has been announced to ship with .NET 4.5? Or is it a whole different product? I'm just trying to figure out the "best" way to do a REST service with WCF on .NET 4.0. Thanks for your help.
    • The WCF WebApi was incorporated into ASP.NET MVC Beta4 and is now the ASP.NET Web API. This will be your best bet.
  • How to use this service?
    3 Posts | Last post June 24, 2011
    • Hi Ron:
         I want to use this service,it show error when i add this service referrence,can u provide the 
      method for me,thx!
    • Add service reference works only for SOAP services.  To work with a REST service you have to use an Http client.  Take a look at the test code and you will see how I did it.
    • It goes well now,thank you very much!
      I have another question that need your recommend,which like this:
      I want to get a resource feed using RSS,it prompt the convert error when i use JsonConvert to deserialize Rss20FeedFormatter object,below is my back code:
              protected void QueryRss20FeedFormatter(object sender, EventArgs e)
                  string wcfUri = "http://localhost/CannonicalRESTWebApp/CannonicalRESTService.svc/rss";
                  var client = new HttpClient();
                  var response = client.Get(wcfUri);
                  var json = response.Content.ReadAsString();
                  Rss20FeedFormatter re = JsonConvert.DeserializeObject<Rss20FeedFormatter>(json); //将实体反序列化
      this last line prompt this error,waitin for your suggestion.
  • Logging?
    2 Posts | Last post June 03, 2011
    • Is there a way to log to a txt file for each testmethod?  I have been looking for a place that doesnt need to construct more than once.
    • WCF has a great tracing infrastructure.  If you need diagnostic tracing that would be the way to go.  Otherwise you could implement a WCF Behavior and do your logging from there.  See the WCF REST API Key example. http://blogs.msdn.com/b/endpoint/archive/2010/06/17/endpoint-tv-how-to-do-api-key-verification-with-a-wcf-webhttp-rest-service.aspx
  • How about security?
    2 Posts | Last post May 23, 2011
    • Hey Ron,
      Thanks for this. It has really helped me get started with my own REST service. Now I'm to the point where I need to add authorization to my service. I know there is no 'standard' for this but there are some things in the HTTP spec that one should probably use... like the Authorization header. Do you have any half-baked samples lying around implementing an authorization scheme in REST?
    • Great question... I really need to spend some time on this.  Don't know the answer right now.