Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF:maxStringContentLength始终设置为8192_Wcf_Maxstringcontentlength - Fatal编程技术网

WCF:maxStringContentLength始终设置为8192

WCF:maxStringContentLength始终设置为8192,wcf,maxstringcontentlength,Wcf,Maxstringcontentlength,我需要将maxStringContentLength更改为大于8192的值,但尚未成功执行。如果我的WCF服务接收的数据量大于8192字节,它将生成一个异常。我已经搜遍了,似乎没有任何帮助。我应该指出,异常来自服务器。忘记客户端吧,因为我看到的异常是直接从服务器上的WCF生成的。以下是我的web.config设置: <system.serviceModel> <behaviors> <serviceBehaviors> <beha

我需要将maxStringContentLength更改为大于8192的值,但尚未成功执行。如果我的WCF服务接收的数据量大于8192字节,它将生成一个异常。我已经搜遍了,似乎没有任何帮助。我应该指出,异常来自服务器。忘记客户端吧,因为我看到的异常是直接从服务器上的WCF生成的。以下是我的web.config设置:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="DevServiceBehavior" >
        <serviceMetadata httpGetEnabled="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="DeveloperService"
             behaviorConfiguration="DevServiceBehavior" >
      <endpoint address="mtom"
                binding="basicHttpBinding"
                bindingConfiguration="Binding_DevService"
                contract="DeveloperService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint contract="IMetadataExchange"
                binding="mexHttpBinding"
                address="mex" />
    </service>
  </services>
  <bindings>
    <basicHttpBinding>
      <binding name="Binding_DevService"
               messageEncoding="Mtom"
               openTimeout="00:02:00"
               sendTimeout="00:02:00"
               maxBufferPoolSize ="41943040"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="500"
                      maxArrayLength="20000000"
                      maxStringContentLength="20000000" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                              multipleSiteBindingsEnabled="true"/>
</system.serviceModel>


也更新客户端配置。在中设置阅读器的配额,并在绑定部分设置其属性。

默认情况下,最新版本的WCF实际上会设置默认值,而json是默认值。不清楚的是WCF使用的是哪种默认绑定。结果是webHttpBinding。您还将在web上看到大量示例,显示应用于服务方法的属性,例如[WebGet]。该方法根本不需要属性。要使maxStringContentLength生效,需要正确设置绑定和行为。以下是web.config文件中的正确条目:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="jsonBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="DevServiceBehavior" >
        <serviceMetadata httpGetEnabled="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="DeveloperService" behaviorConfiguration="DevServiceBehavior" >
      <endpoint address="" binding="webHttpBinding" contract="DeveloperService" bindingConfiguration="webHttpBindingDev" behaviorConfiguration="jsonBehavior">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
  </services>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBindingDev">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </webHttpBinding>
  </bindings> 
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>


您可以添加异常详细信息吗?您必须配置服务器和客户端配置。您的服务类(包括名称空间)的名称是什么?如果您发送较小的请求(其配额未超过),服务器是否使用“普通”XML或MTOM(在fiddler中查找)进行响应。如果是前者,那么这就是Ladislav指出的问题-配置中的服务名称不正确(您需要使用与.svc文件中相同的名称)Carlosfigueira:当数据量没有超过时,服务工作正常。这里有一个指向与读卡器配额相关的MSDN文章的链接。这几乎在所有情况下都是一件重要的事情。