我从一些存根调用WCF服务。问题是,我不能在客户端拥有app.config
。所以我在我的代码中设置值。
服务web.config
显示如下值:
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IStatementsManagerService" openTimeout="00:10:00"
closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="true"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="567890" maxBufferPoolSize="524288" maxReceivedMessageSize="567890"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<!--<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>-->
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="PathFINDER.Services.IStatementsManagerService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStatementsManagerService"
contract="PopulateReqProServiceERReqs.IStatementsManagerService"
name="BasicHttpBinding_IStatementsManagerService" />
<endpoint kind="mexEndpoint" address="mex" />
</service>
</services>
</system.serviceModel>
客户端的代码是这样的:
BasicHttpBinding binding = new BasicHttpBinding();
//System.ServiceModel.Channels.Binding binding = new BasicHttpBinding();
TimeSpan t = new TimeSpan(0, 2, 0);
binding.Name = "BasicHttpBinding_IStatementsManagerService";
binding.CloseTimeout = new TimeSpan(00, 01, 00);
binding.OpenTimeout = new TimeSpan(00, 01, 00);
binding.ReceiveTimeout = new TimeSpan(00, 10, 00);
binding.SendTimeout = new TimeSpan(00, 10, 00);
binding.AllowCookies = false;
binding.BypassProxyOnLocal = false;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.MaxBufferSize = 567890;
binding.MaxBufferPoolSize = 524288;
binding.MaxReceivedMessageSize = 567890;
binding.MessageEncoding = WSMessageEncoding.Text;
//binding.TextEncoding= "utf-8";
binding.TransferMode = TransferMode.Buffered;
binding.UseDefaultWebProxy = true;
binding.ReaderQuotas.MaxDepth=2147483647;
binding.ReaderQuotas.MaxStringContentLength=2147483647;
binding.ReaderQuotas.MaxArrayLength=2147483647;
binding.ReaderQuotas.MaxBytesPerRead=2147483647;
binding.ReaderQuotas.MaxNameTableCharCount=2147483647;
string ServiceUrl = "http://localhost:56620/StatementsManagerService.svc";
System.ServiceModel.EndpointAddress remoteAddress = new System.ServiceModel.EndpointAddress(ServiceUrl);
PopulateReqProService.StatementsManagerServiceClient Smsc = new PopulateReqProService.StatementsManagerServiceClient(binding, remoteAddress);
blnReturn = Smsc.MyMethod(MyParam);
但问题是,当我在参数中调用包含大量数据的服务时,它会失败,并且在svclog文件中我可以清楚地看到异常:
传入邮件的最大邮件大小限额(65536) 被超过了。要增加配额,请使用MaxReceivedMessageSize 适当的绑定元素上的属性。
有人可以帮忙吗?我没有得到任何线索。
答案 0 :(得分:2)
您只需要增加MaxReceivedMessageSize属性,因为您调用的方法返回的数据长度大于567890.只需在服务器和客户端上试验这些值。
答案 1 :(得分:2)
您还需要设置binding
的{{1}}部分中指定的值(在客户端<ReaderQuotas>
代码中)!
web.config
然后它应该工作:
答案 2 :(得分:1)
在行为方面,您需要设置此项,请尝试以下代码:
maxItemsInObjectGraph="2147483646"
我知道这是一个非常古老的问题,但仍然存在。