加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

wcf – aspNetCompatibilityEnabled =“true”

发布时间:2020-12-16 09:49:31 所属栏目:asp.Net 来源:网络整理
导读:我创建了一个Azure Web应用程序,其中包含一个ASP.NET Web,其中还包含一些 JSON WCF服务.我真的不太了解WCF服务模型,以确保我做得对,这看起来对你来说是否正确?是否有其他服务模型配置更好的可扩展性,更多的最大并发连接等? system.serviceModel behaviors
我创建了一个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等.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读