WCF 服务 - 尽管最大值很大,但根据大小几乎立即拒绝数据

标签 wcf size max

我有一个 WCF 网络服务,其中包含 1 个采用单个字符串参数的正常运行的网络方法。 我有一个引用 WCF 网络服务的 WinForms 应用程序,它全部在 .NET 4.0 上运行。

问题是,当我调用带有太多字符串数据(大约 4MB)的 web 方法时,在我的本地机器(Win 7 Pro 64 位,IIS 7)上调试客户端和服务器时,我得到以下错误(内部异常(exception),异常(exception)):

The request was aborted: The request was canceled.

An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel.

在生产服务器上运行时,我收到一条不同的消息(愚蠢的是我没有复制它)说服务器可能已中止连接或类似内容。

如果我将数据减少到大约一半 (2MB),它就可以正常工作。令人沮丧的是,我已经最大化了所有配置设置,重置了 IIS,重新启动了我的机器,但它仍然存在。

Web 服务验证代码被命中,验证用户是否正常,然后一旦它退出验证,就会将上面的消息转储回客户端。验证方法(我的代码)中的堆栈跟踪仅显示 .NET 内容,因此我的代码不再需要调试,8(.

在服务器端,我在 web.config 中有这个:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
    <service name="MyNS.MyService" behaviorConfiguration="MyNS.MyServiceBehavior">
        <endpoint binding="wsHttpBinding" bindingConfiguration="httpWithMessageSecurity" contract="MyNS..MyService">
            <identity>
                <dns value="localhost"/>
            </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="MyNS.MyServiceBehavior">
            <serviceCredentials>
                <serviceCertificate findValue="Server" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
                <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNS.Validators.MyServiceUserValidator, MyNS./>
            </serviceCredentials>
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
<bindings>
    <wsHttpBinding>
        <binding name="httpWithMessageSecurity" 
                 maxReceivedMessageSize="2147483647"
                 maxBufferPoolSize="2147483647">
            <readerQuotas
                maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647"
                maxArrayLength="2147483647"
                maxStringContentLength="2147483647"/>
            <security mode="Message">
                <message clientCredentialType="UserName"/>
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

在客户端,我在 app.config 中有这个:

<system.serviceModel>
<bindings>
    <wsHttpBinding>
        <binding name="serviceHttpBinding"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 messageEncoding="Text"
                 textEncoding="utf-8"
                 sendTimeout="01:00:00"
                 closeTimeout="00:00:20"
                 openTimeout="00:00:20"
                 receiveTimeout="00:20:00">
            <readerQuotas
                maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647"
                maxArrayLength="2147483647"
                maxStringContentLength="2147483647"/>
            <security mode="Message">
                <message clientCredentialType="UserName" negotiateServiceCredential="true"
                  algorithmSuite="Default" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>
<behaviors>
    <endpointBehaviors>
        <behavior name="clientServerBehaviour">
            <clientCredentials>
                <serviceCertificate>
                    <authentication certificateValidationMode="PeerOrChainTrust"/>
                </serviceCertificate>
            </clientCredentials>
        </behavior>
    </endpointBehaviors>
</behaviors>
<client>
    <endpoint address="http://mymachine/TheServices/Services/MyService.svc"
      binding="wsHttpBinding" bindingConfiguration="serviceHttpBinding"
      contract="DirectorySubmitService.IDirectorySubmitService" name="WSHttpBinding_IDirectorySubmitService">
        <identity>
            <dns value="Server" />
        </identity>
    </endpoint>
</client>

编辑 1: 在 VS 中启用调试符号后,在 WCF 服务中的验证代码完成后,我得到以下异常: System.Web.HttpException:超过最大长度 堆栈:System.Web.HttpRequest.GetEntireRawContent()

然后: System.ServiceModel.CommunicationException:超过最大长度 堆栈:System.ServiceModel.Activation.HostedHttpRequestAsyncResult.GetInputStream()

随后的 CommunicationExceptions 与 Channels 等有关。但都是相同的错误消息。

我都检查了 IIS 中设置为 30 MB 的应用程序池作为请求限制,所以我已经用完了我可以增加的最大限制,所以这条消息是一个真正的耳光。

如有任何帮助,我们将不胜感激。

最佳答案

事实证明,我用来将请求限制设置为 50MB 的 httpRuntime web.config 元素被忽略了,因为我指定的位置路径缺少文件夹级别,即 location path="MyService.svc "而不是 location path="Services/MyService.svc"。

最终结果是它使用了默认的 4MB 限制,这导致了最大长度超出消息,因为情况确实如此。

呸!

关于WCF 服务 - 尽管最大值很大,但根据大小几乎立即拒绝数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4725735/

相关文章:

c - getchar() 用于从输入中排除字符

javascript - TypeScript - 数字更大还是更小验证仅当数字具有相同的 'length' 时才会响应

javascript - 尝试返回数组的最小值、最大值和平均值

.net - 使用自定义ServiceHostFactory时是否需要Dispose()?

c# - 集合接口(interface)和 WCF

c# - 什么安全类型最适合 WCF (wsHttpBinding) 服务及其跨域客户端,并且两者都使用相同的数据库

html - 如何使 div/video 始终为浏览器窗口的大小,并固定在特定位置

python-3.x - Python 3.4 Tkinter - 无法为 PanedWindow 中的框架提供大小

cocoa - 获取nswindow的大小

wcf - 元素 ':item' 包含映射到名称 'http://...:Location' 的类型的数据。反序列化器不知道映射到 thi 的任何类型