wcf – aspNetCompatibilityEnabled =“true”
我创建了一个Azure Web应用程序,其中包含一个ASP.NET Web,其中还包含一些
JSON WCF服务.我真的不太了解WCF服务模型,以确保我做得对,这看起来对你来说是否正确?是否有其他服务模型配置更好的可扩展性,更多的最大并发连接等?
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> <system.net> <settings> <!-- See http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83 --> <servicePointManager expect100Continue="false" /> </settings> </system.net> 这有效但我偶尔会在我的开发环境中得到意外的连接丢失(超时)而没有HTTP错误代码让我担心. 2011年11月24日更新 web.config中 <system.net> <connectionManagement> <!-- See http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83 --> <add address="*" maxconnection="48" /> </connectionManagement> </system.net> 我怀疑可能是Visual Studio Web服务器导致Ajax调用超时,几分钟后服务开始再次接受请求.这是我的完整设置,你能看出问题是什么吗?我只对该服务进行一次Ajax调用. Inferface IExample.cs: using System.ServiceModel; using System.ServiceModel.Web; namespace WebPages.Interfaces { [ServiceContract] public interface IExample { [OperationContract] [WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json)] string GetSomething(string id); } } ExampleService.svc.cs标记 <%@ ServiceHost Language="C#" Debug="true" Service="WebPages.Interfaces.ExampleService" CodeBehind="ExampleService.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %> ExampleService.svc.cs代码隐藏 namespace WebPages.Interfaces { [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ExampleService : IExample { string JsonSerializeSomething(Something something) { var serializer = new DataContractJsonSerializer(something.GetType()); var memoryStream = new MemoryStream(); serializer.WriteObject(memoryStream,something); return Encoding.Default.GetString(memoryStream.ToArray()); } public string GetSomething(string id) { var something = DoSomeBusinessLogic(id); return JsonSerializeSomething(something); } } } 来自客户端的jQuery调用 function _callServiceInterface(id,delegate) { var restApiCall = "Interfaces/ExampleService.svc/GetSomething?id=" + escape(id); $.getJSON(restApiCall,delegate); } function _getSomethingFromService() { _callServiceInterface('123',function (result) { var parsedResult = $.parseJSON(result); $('#info').html(result.SomethingReturnedFromServiceCall); } ); } 更新 我想我知道现在的问题是什么; WCF服务似乎是默认的单一威胁(来源:http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.SERVICEMODEL.SERVICEBEHAVIORATTRIBUTE.CONCURRENCYMODE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true).这解释了为什么我的Ajax调用获得超时,被另一个线程阻止.这段代码应该可以更好地工作: ExampleService.svc.cs [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,InstanceContextMode = InstanceContextMode.PerSession,IncludeExceptionDetailInFaults = false,MaxItemsInObjectGraph = Int32.MaxValue)] //[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ExampleService : IExample web.config中 <system.serviceModel> <protocolMapping> <add scheme="http" binding="webHttpBinding" bindingConfiguration="" /> </protocolMapping> <behaviors> <endpointBehaviors> <behavior name=""> <webHttp defaultOutgoingResponseFormat="Json" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> ExampleService.svc <%@ ServiceHost Language="C#" Debug="true" Service="WebPages.Interfaces.TagService" CodeBehind="TagService.svc.cs" %> 2011年10月9日更新 我想我在Locking with ConcurrencyMode.Multiple and InstanceContextMode.PerCall得到了我需要的答案 aspNetCompatibilityEnabled =“false”表示无法在我的WCF代码中访问HttpContext,ASP.NET Sessions等. 解决方法
我想我得到了我需要的答案
Locking with ConcurrencyMode.Multiple and InstanceContextMode.PerCall
aspNetCompatibilityEnabled =“false”表示无法在我的WCF代码中访问HttpContext,ASP.NET Sessions等. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net(c#)动态修改webservice的地址和端口(动态修改配置
- 如何在VS 2010中停止调试时正常退出ASP.NET应用程序?
- ASP.net Web窗体,在编译时获取aspx /视图错误?
- CKEditor数据绑定在asp.net核心mvc中
- asp.net – 需要一个Web表单示例编辑带子项的父实体对象
- asp.net-core – 为Microsoft.CodeAnalysis.Common检测到版
- asp.net-mvc – 如何将Ninject与HttpClient一起使用
- asp.net-mvc – WebApiConfig.cs和RouteConfig.cs之间的区别
- asp.net – 具有不同按钮类型的Asp按钮
- asp.net – Facebook和G的自定义LINK共享URL
- ASP.NET Excel导出编码问题
- 如何使ASP.NET MVC应用程序多语言?
- asp.net – 在jQuery对话框中的窗体中,MVC中通常
- asp.net-mvc-3 – ASP.NET MVC 3:当BeginForm在
- asp.net-mvc – 如何编写C#Extension方法将Domai
- asp.net-mvc – 死简单的ASP.NET MVC 5密码保护?
- .NET Core采用的全新配置系统[5]: 聊聊默认支持的
- iis – 我应该为我的生产服务器使用processModel
- asp.net-mvc-3 – 单元测试一个文件上传,怎么样?
- asp.net-mvc – mvc4future无法在ASP.NET MVC 5中