I am calling a WCF service from some stub. The issue is that, I can not have the app.config
on the client side. So I am setting the values from within my code.
The service web.config
shows values like this:
<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>
And the code on the client side is like this:
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);
But the issue is that when I call the service with lots of data in the parameter, it fails with a protocoleception and in the svclog file I can clearly see the exception as:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
Can somebody help? I am not getting any clue.
You also need to set the values (on your client side binding
in code) that you specify in the <ReaderQuotas>
section of your web.config
!
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
then it should work:
You just need to increase the MaxReceivedMessageSize property as the method you are calling is returning data with a length greater than 567890. Just experiment with the values on both the server and the client.
In behavior, you will need to set this, try below code:
maxItemsInObjectGraph="2147483646"
I know this is very old question, but still.
精彩评论