发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
在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>
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))); }
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; } }
5.运行调试, 刚运行的时候 运行服务,在当前地址后面添加上面的服务节点
可以再路径后面添加“help/”查看服务的各个方法。 到此结束!
来自: 昵称10504424 > 《工作》
0条评论
发表
请遵守用户 评论公约
简单五步创建一个WCF Rest Service
简单五步创建一个WCF Rest Service。} } private IList<Student> _Users = new List<Student>{ ...
WCF 开启消息日志功能
WCF 开启消息日志功能生产环境。若要增强调试功能,也应将其他跟踪源(System.ServiceModel.MessageLogging)添加到配置中以启用消息日志记录。--开启日志功能--> <system.diagnostics> <t...
WCF之旅(1):创建一个简单的WCF程序
这个Project引用Artech.WCFService.Contract、Artech.WCFService.Service和System.ServiceModel DLL。//Create a Binding for Endpoint....
C#学习之简单的WCF例子
因为在这个类作为服务端(可以这么认为),里面的方法就是为了给客户端使用的,那么就要在声明的方法前加[OperationContract],但只有加...
我的WCF之旅(1):创建一个简单的WCF程序
为了使读者对基于WCF的编程模型有一个直观的映像,我将带领读者一步一步地创建一个完整的WCF应用。基于IIS的服务寄宿要求相应的WCF服务...
WCF配置文件全攻略
—定义一个或多个系统提供的binding元素,例如<basicHttpBinding> --> <!—也可以是自定义的binding元素,如<customBinding>. --> <binding> <!—例如<...
一步一步学Linq to sql(十):分层构架的例子
一步一步学Linq to sql(十):分层构架的例子。l C引用B、D、System.ServiceModel以及System.Data.Linq程序集。首先我们可以定义出留言簿数据访问服务的契约(接口),把如下的代码保存为IDat...
win7提速
一直以来Windows都自带了一些系统声音主题,当执行不同操作的时候会有各种音效,不过这些声音对很多人来说没什么用处,而且在你音量调到较高的时候,突然蹦出来一下会让人很不爽,因此让Windows“闭嘴...
FastReport创建托管在windows服务中的WCF服务
FastReport创建托管在windows服务中的WCF服务在慧都之前的几篇文章中也提到了,报表开发工具FastReport .NET最新的WCF服务库FastReport....
微信扫码,在手机上查看选中内容