WCF服务-尽管最大值很大,但数据会根据大小立即被拒绝
我有一个WCF web服务,其中有一个功能正常的web方法,它只接受一个字符串参数。 我有一个WinForms应用程序,它引用了WCF Web服务,并且都运行在.NET 4.0上 问题是,当我在本地机器(Win 7 Pro 64位,IIS 7)上调试客户机和服务器时,调用web方法时,字符串数据的数据太多(大约4MB),我得到以下错误(内部异常,异常): 请求已中止:请求已终止 取消了 错误(请求已中止:请求已终止) 请求已取消。)发生时 通过HTTP传输数据 频道 在生产服务器上运行时,我收到一条不同的消息(愚蠢的,我没有复制它),说服务器上的某些东西可能已中止连接或类似操作 如果我将数据减少到大约一半(2MB),它就可以正常工作。令人沮丧的是,我已经将所有配置设置设为最大,重置了IIS,重新启动了我的机器,但它仍然存在 web服务验证代码被命中,验证用户是否正常,然后一旦退出验证,就会将上面的消息转储回客户端。验证方法(我的代码)中的堆栈跟踪只显示.NET内容,因此没有更多的代码需要调试,8( 在服务器端,我在web.config中有以下内容:WCF服务-尽管最大值很大,但数据会根据大小立即被拒绝,wcf,size,max,Wcf,Size,Max,我有一个WCF web服务,其中有一个功能正常的web方法,它只接受一个字符串参数。 我有一个WinForms应用程序,它引用了WCF Web服务,并且都运行在.NET 4.0上 问题是,当我在本地机器(Win 7 Pro 64位,IIS 7)上调试客户机和服务器时,调用web方法时,字符串数据的数据太多(大约4MB),我得到以下错误(内部异常,异常): 请求已中止:请求已终止 取消了 错误(请求已中止:请求已终止) 请求已取消。)发生时 通过HTTP传输数据 频道 在生产服务器上运行时,我收到
<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>
事实证明,我用于将请求限制设置为50MB的httpRuntime web.config元素被忽略,因为我指定的位置路径缺少文件夹级别,即location path=“MyService.svc”而不是location path=“Services/MyService.svc”
最终的结果是,它使用了默认的4MB限制,这导致消息的最大长度超过了消息,因为事实正是如此
Doh!这条评论让我明白了一个想法,即httpRuntime元素必须位于web服务配置中,才能让客户端web应用正常工作
<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>