Udostępnij za pośrednictwem


Notes on RESTful Architecture – II. Read Only RESTful Services

From the book RESTful .NET: Build and Consume RESTful Web Services with .NET 3.5.

RESTful binding, behavior, hosting, and contracts

WebHttpBinding – uses http transport and text encoder.

WebBehavior – end point behavior to dispatch messages based on URIs and HTTP verbs.

WebSericeHost – provides RSTful services hosting configuration [WebServuceHostFactory for IIS/WAS].

WebOperationContext – contains state of the incoming request and outgoing response.

  • QueryParameters – holds the collections of query string parameters. Available in IncomdingRequest of WebOperationContext.

WebGetAttribute – applied to methods to handle GET requests

WebInvokeAttribute – applied to methods to handle POST, PUT, DELETE.

  • Method - a property that specifies what HTTP method to use [POST – default, PUT, or DELETE]

UriTemplate – specifies the template, mapping between the URI and a method

  • “/{Variable}/{Variable}/{Variable}”
  • “*”
  • “/”
  • “{/{Variable}/*}”
  • “/Literal/{Variable}”
  • “/Literal/NestedLiteralSpecialCase”
  • “/Search?q={query}” – for passing parametrs via query string and collecting it using QueryParamenters object.

Serialization methods

Message - represents return value for RESTful service

  • Not usually used with non-RESTful WCF [strong type are used instead]
  • More complex coding to process the message
  • Complete control of the XML

DataContract 

  • Preferred method non-RESTful regular WCF
  • Cannot create attributes, elements only

XnkSerializer

  • Better for RESTful WCF
  • [XmlSerialization()] for [OperationContract]
  • Can create attributes vs. elements [XmlAttribute(Attribute=”name”)] instead [DataMemeber]

Hybrid (DataContract + Message)

  • Use DataContract for serialization.
  • Use Message.CreateMessage for return type.