How to create RESTful WCF Service
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:44 点击:次
/*by garcon1986*/
p>
p>Based on my last post about how to create, host, test and consume WCF Service, here we will discover how to create RESTful WCF Service.
p>
p>“Representational State Transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web. REST has emerged as a predominant Web service design model.” from wiki
p>
p>“Those principles of REST service are:
p>User agents interact with resources, and resources are anything that can be named and represented. Each resource can be addressed via a unique Uniform Resource Identifier (URI).
p>Interaction with resources (located through their unique URIs) is accomplished using a uniform interface of the HTTP standard verbs (GET, POST, PUT, and DELETE). Also important in the interaction is the declaration of the resource's media type, which is designated using the HTTP Content-Type header. (XHTML, XML, JPG, PNG, and JSON are some well-known media types.)
p>Resources are self-descriptive. All the information necessary to process a request on a resource is contained inside the request itself (which allows services to be stateless).
p>Resources contain links to other resources (hyper-media).” from microsoft
p>
p>We don't need to change our class "HelloWorldService", so it should always be:
p>[csharp]
p>namespace MyWCFServices
p>{
p> /// <summary>
p> /// Create a service class and implement service interface
p> /// </summary>
p> public class HelloWorldService : IHelloWorldService
p> {
p> public string GetMessage(string name)
p> {
p> return "Hello world from " + name + "!";
p> }
p>
p> public string GetPerson(string person)
p> {
p> return "Person name :" + person + "!";
p> }
p> }
p>}
p>
p>While, the inteface "IHelloWorldService", should be modified.
p>[csharp]
p>using System.ServiceModel; //used for ServiceContract. it contains the types necessary to build Windows Communication Foundation (WCF) service and client applications.
p>using System.ServiceModel.Web;
p>
p>namespace MyWCFServices
p>{
p> [ServiceContract]
p> public interface IHelloWorldService
p> {
p> [OperationContract]
p> [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml,
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>