国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

vs2013下的WCFRest 模板開發WCF

2019-11-15 02:31:52
字體:
來源:轉載
供稿:網友

vs2013下的WCFRest 模板開發WCF

在vs2013下使用wcfRestservice40 是安裝不成功的,嘗試多遍,都是這樣。查看以前vs2012做的wcfrest,經過調教,終于在vs2013下也可以了!

1.新建wcf服務應用程序

2.調制配置文件

<?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

里面代碼:

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類庫 (以后作為服務的節點)

[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.運行調試,

剛運行的時候

運行服務,在當前地址后面添加上面的服務節點

可以再路徑后面添加“help/”查看服務的各個方法。

到此結束!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永胜县| 新巴尔虎右旗| 长沙市| 上犹县| 房产| 巴中市| 五华县| 盘山县| 嵊泗县| 新宁县| 东方市| 色达县| 福泉市| 合水县| 温泉县| 石阡县| 昌邑市| 景德镇市| 寿宁县| 蕉岭县| 曲沃县| 皮山县| 东兰县| 辽宁省| 抚顺市| 仪征市| 连平县| 永川市| 富平县| 山丹县| 称多县| 都安| 峨山| 绥宁县| 洮南市| 韶关市| 岫岩| 临漳县| 陆川县| 汽车| 澄江县|