首页 > 其他 > 详细

vs2013下的WCFRest 模板开发WCF

时间:2014-02-27 23:20:47      阅读:602      评论:0      收藏:0      [点我收藏+]

在vs2013下使用wcfRestservice40 是安装不成功的,尝试多遍,都是这样。查看以前vs2012做的wcfrest,经过调教,终于在vs2013下也可以了!

1.新建wcf服务应用程序

2.调制配置文件

bubuko.com,布布扣
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </modules>
  </system.webServer>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
    
  </system.serviceModel>
</configuration>
View Code

3.添加全局应用程序类 Global.asax

  里面代码:

bubuko.com,布布扣
void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();
        }

        private void RegisterRoutes()
        {
            RouteTable.Routes.Add( new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
            //RouteTable.Routes.Add("test", new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
        }
View Code

4.新建Service1.cs类库 (以后作为服务的节点)

bubuko.com,布布扣
[ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class Service1
    {
        [WebGet(UriTemplate = "")]
        public List<SampleItem> GetCollection()
        {
            return  new List<SampleItem>(){new SampleItem(){Id = 1,StringValue = "Hello"}};
        }
    }
    public class SampleItem
    {
        public int Id { get; set; }
        public string StringValue { get; set; }
    }
Service1

5.运行调试,

刚运行的时候bubuko.com,布布扣

运行服务,在当前地址后面添加上面的服务节点

bubuko.com,布布扣

可以再路径后面添加“help/”查看服务的各个方法。

到此结束!

vs2013下的WCFRest 模板开发WCF,布布扣,bubuko.com

vs2013下的WCFRest 模板开发WCF

原文:http://www.cnblogs.com/kongyz/p/vs2013_wcfRest.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!