您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > ASP >

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,   
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • WAP常见问题问答大全(四)
  • ASP开发必备:WEB打印代码大全
  • ASP调用系统ping命令
  • asp缓存技术
  • ASP教程:第三篇 ASP基础
  • 用ASP+XML打造留言本(4)
  • 关于ASP Recordset 分页出现负数解决方法及建议
  • 用asp怎样编写文档搜索页面(5)
  • ASP处理多关键词查询实例代码
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1