网站服务器空间价格网站开发顶岗周记
news/
2025/9/30 19:51:32/
文章来源:
网站服务器空间价格,网站开发顶岗周记,网站图片相册代码,wordpress 上传模板打开vs2010 在工具选项中选择扩展管理器——联机库 安装WCF REST Service Template 40(CS)模板 安装后新建wcf服务应用程序#xff0c;删除默认建立的文件。 新建RestWcf4HelpPage.svc#xff0c;代码如下 using System;
using System.Collections.Generic;
using System.Lin…打开vs2010 在工具选项中选择扩展管理器——联机库 安装WCF REST Service Template 40(CS)模板 安装后新建wcf服务应用程序删除默认建立的文件。 新建RestWcf4HelpPage.svc代码如下 using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;namespace RestWcf
{[ServiceBehavior(IncludeExceptionDetailInFaultsfalse)][AspNetCompatibilityRequirements(RequirementsMode AspNetCompatibilityRequirementsMode.Allowed)]public class RestWcf4HelpPage : IRestWcf4HelpPage{#region IRestWcf4HelpPage 成员[WebGet(UriTemplate/Rest/Get/{id})]public string GetData(string id){return Hello Rest GetData;}[WebInvoke(UriTemplate/Rest/Add/{id},MethodPOST)]public string AddData(string id){return Hello Rest AddData;}[WebInvoke(UriTemplate /Rest/Update/{id}, Method PUT)]public string UpdateData(string id){return Hello Rest UpdateData;}[WebInvoke(UriTemplate /Rest/Delete/{id}, Method Delete)]public string DeleteData(string id){return Hello Rest DeleteData;}#endregion}[XmlSerializerFormat][ServiceContract]interface IRestWcf4HelpPage{[OperationContract]string GetData(string id);[OperationContract]string AddData(string id);[OperationContract]string UpdateData(string id);[OperationContract]string DeleteData(string id);}
} View Code 然后在建立RestWcf4Cache.svc代码如下 using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;namespace RestWcf
{[ServiceBehavior(IncludeExceptionDetailInFaultsfalse)][AspNetCompatibilityRequirements(RequirementsMode AspNetCompatibilityRequirementsMode.Allowed)]public class RestWcf4Cache:IRestWcf4Cache{#region IRestWcf4Cache 成员[AspNetCacheProfile(CacheFor10Senconds)][WebGet(UriTemplate /Rest/Get/{id})]public string GetData(string id){return Hello Rest GetData DateTime.Now.ToString();}#endregion}[ServiceContract]interface IRestWcf4Cache{[OperationContract]string GetData(string id);}
} View Code 然后在配置web.config文件其中duration值缓存的有效时间。 ?xml version1.0 encodingutf-8?
configurationsystem.webcompilation debugtrue targetFramework4.0 /cachingoutputCacheSettingsoutputCacheProfiles add nameCacheFor10Senconds duration10 varyByParamformat/add nameCacheFor30Senconds duration30 varyByParamformat//outputCacheProfiles/outputCacheSettings/caching/system.websystem.serviceModelservicesservice nameRestWcf.RestWcf4HelpPageendpoint address behaviorConfigurationRestWcf4HelpPageBehaviorbindingwebHttpBinding contractRestWcf.IRestWcf4HelpPage //serviceservice nameRestWcf.RestWcf4Cacheendpoint address behaviorConfigurationRestWcf4CacheBehaviorbindingwebHttpBinding contractRestWcf.IRestWcf4Cache //service/servicesbehaviorsendpointBehaviorsbehavior nameRestWcf4HelpPageBehaviorwebHttp helpEnabledtrue //behaviorbehavior nameRestWcf4CacheBehaviorwebHttp helpEnabledtrue //behavior/endpointBehaviorsserviceBehaviorsbehavior nameserviceMetadata httpGetEnabledtrue /serviceDebug includeExceptionDetailInFaultsfalse //behavior/serviceBehaviors/behaviorsserviceHostingEnvironment aspNetCompatibilityEnabledtruemultipleSiteBindingsEnabledtrue //system.serviceModelsystem.webServermodules runAllManagedModulesForAllRequeststrue//system.webServer/configuration 帮助页面的效果如下图 get请求结果如下图 缓存效果如图,缓存的时间设置为10s在10s内结果都是下图超过时间后就是另一个结果了 转载于:https://www.cnblogs.com/ZJ199012/p/4078890.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923202.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!