Wcf rest编程
   
    Restful
   
    一种软件架构风格,设计风格而
    
     不是
    
    标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。(关于这种编程风格大家可以百度下)
   
    Wcf
   
前面已经讲过,但自己书中不会创建一个restful风格的服务,最近看到一份外文博客分享给大家,这里这是创建,具体原理,我能懂了再分享个大家。
    Step1
   
新建wcf服务应用程序
    
    
   
    Step2
   
    
   
添加新建项
    
    
   
    Step3修改
   
修改接口
[ServiceContract]
    public interface IRestService
    {
        [WebInvoke(Method = "GET",
           ResponseFormat = WebMessageFormat.Xml,
           BodyStyle = WebMessageBodyStyle.Wrapped,
           UriTemplate = "xml/{id}")]
        string XMLData(stringid);
 
        [WebInvoke(Method = "Get",
            ResponseFormat = WebMessageFormat.Json,
               BodyStyle = WebMessageBodyStyle.Wrapped,
               UriTemplate = "Json/{id}")]
        string JsonDate(stringid);
    }实现方法
  public class RestService : IRestService
    {
        public stringXMLData(string id)
        {
            return "you requestproduce" + id;
        }
 
        public stringJsonDate(string id)
        {
            return "you requestproduce" + id;
        }
    }修改XML文档
<system.serviceModel>
   <behaviors>
     <serviceBehaviors>
       <behaviorname="ServiceBehavior">
         <!--为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
         <serviceMetadatahttpGetEnabled="true"/>
         <!--要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
         <serviceDebugincludeExceptionDetailInFaults="false"/>
       </behavior>
     </serviceBehaviors>
     <endpointBehaviors>
       <behaviorname="web">
         <webHttp/>
       </behavior>
     </endpointBehaviors>
   </behaviors>
   <services>
     <servicename="Restful.RestService"behaviorConfiguration="ServiceBehavior">
       <endpointaddress=""binding="webHttpBinding"contract="Restful.IRestService"behaviorConfiguration="web">
       </endpoint>
     </service>
   </services>
   <serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
 </system.serviceModel>
    运行
   
    
   
    总结
   
慢慢多学,天天学。走编程解决问题。
 
