Use WCF to create a rest API

Source: Internet
Author: User
Tags oauth

Aaron Sloman and Haider Sabri talked about how to "use WCF to create a rest API" in mix08. They introduced a rest application named restchess.ProgramExample.

Aaron Sloman first talked about some background information that supports rest in WCF. Then, Haider Sabri briefly introduces the main features of rest and rest. According to Haider, The key advantages of rest are:

      • Low learning threshold
      • Roa follows the Web semantics ...... APIS suitable for Web Services
      • Flexible and variable response formats

He believes that "if the client is unknown, rest is the best choice when creating a common API ".

WCF supports rest through the Web programming model. This model is added in. NET Framework 3.5, including the following concepts:

    • Uri templates & webget/webinvoke
      • They are all features used to map HTTP requests to methods in the class.
    • Webhttpbinding
      • Webhttpbinding is a binding of WCF, which allows content Sending Based on webhttp.
      • You can easily switch between rest and soap APIs.
    • Weboperationcontext
      • Weboperationcontext supports restful processing of requests and responses.

Haider Sabri introduced restchess, a rest API for chess games. Restchess is not only a good example, but also an extension set (custom WCF binding and behavior) to demonstrate rest APIs implemented using the Web Programming Model of WCF ), make up for the defects of the WCF web programming model:

    • Flexible Uris
      • When hosting services in IIS, The. SVC extension of the service is required.
      • Restchess provides a URL rewriting tool and is implemented as an HTTP module in IIS 7.
    • Build a bridge to support low-level rest clients that only support get and post
      • There are two common methods to solve this problem:
        • Custom HTTP Header
        • _ Method query parameters
      • Restchess implements a custom WCF channel, which can distinguish between advanced and low-level rest clients, and modify the message that uses the hidden delete or put method to pass to the appropriate HTTP method through the POST request.
    • Data signature verification request
      • Restchess uses oauth, an open protocol that includes data signatures that supports Secure API verification ".
      • The oauth caller transmits the signature as the query parameter.
      • A custom WCF channel checks whether a request has an oauth key. If the caller is not verified (the key does not exist or cannot be identified) before the request is distributed to the service model ), an exception is thrown.
    • Multiple Forms
      • WCF only supports XML and JSON.
    • Rest Exception Handling
      • The restchess team built an engine that maps exceptions to appropriate HTTP errors.Code.

Although the team completed the task of picking up gaps for the Web Programming Model of WCF, Haider believes: "The flash of WCF lies in its ability to expand and add it, and built on a high level ".

View Original English text:Creating a restful API with WCF

Reprinted from: http://www.infoq.com/cn/news/2008/03/wcf-restful-api

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.