国产探花免费观看_亚洲丰满少妇自慰呻吟_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/”查看服務的各個方法。

到此結束!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卓尼县| 黑龙江省| 泗水县| 鄂尔多斯市| 泸水县| 沙雅县| 新宁县| 江华| 定襄县| 麻城市| 策勒县| 平原县| 尖扎县| 梅州市| 兴山县| 绿春县| 黄梅县| 昔阳县| 山东| 久治县| 平定县| 定西市| 洞口县| 阜城县| 长岛县| 盐池县| 北宁市| 蒙自县| 楚雄市| 大方县| 达拉特旗| 海盐县| 六安市| 长丰县| 柘荣县| 诸暨市| 永安市| 沂源县| 黄冈市| 贵溪市| 哈尔滨市|