Solved

C# Web Service using SOAP and maximum request size

Posted on 2011-09-07
7
1,624 Views
Last Modified: 2013-12-17
I have created a web service whose purpose is to allow records from a database to be synchronized with a central store.  As such it is possible that quite a large amount of data will be passed in the initial synchronization.

I am coding using Visual Studio 2010 and C#.  When trying to pass a particularly large amount of data I am getting an error returned stating that the maximum message size has been exceeded.  I have control of both the client and the web service code and systems.  can I increase the maximum message size or will I have to split my message into smaller packets?
0
Comment
Question by:ChrisMDrew
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:zvytas
ID: 36494420
You can play around with binding options:

<bindings>
    <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
            <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
        </binding>
    </basicHttpBinding>
</bindings>

As you can see there's a maxReceivedMessageSize option. The default is 65,536 bytes. More info here:

http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.maxreceivedmessagesize.aspx
0
 

Author Comment

by:ChrisMDrew
ID: 36494469
Is this something that needs to be changed for the sender and receiver?  I have modified my web.config file for the Web Server and added the lines :-

<system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="Binding1"
                 maxReceivedMessageSize = "1000000">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>

  </system.serviceModel>

As suggested in the MS article but I still get the error...  No way could my message be greater that 1000000 bytes (I hope!)

0
 
LVL 4

Expert Comment

by:guramrit
ID: 36494711
For TransferMode.Buffered, MaxReceivedMessageSize and MaxBufferSize must be the same value. use configurations as told by "zvytas". I'd used wcf in my applications which transfers huge amount of data. I used same configurations for client side too, and works fine.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:ChrisMDrew
ID: 36494766
OK - how do I configure it at the senders side as this is a WinForms application and does not have a web.config file obviously.
0
 
LVL 5

Accepted Solution

by:
zvytas earned 500 total points
ID: 36494962
Chris - if you're using WinForms app you should have app.config - change message size there.
0
 

Author Closing Comment

by:ChrisMDrew
ID: 36494979
Thanks - that seems to be working...
0
 
LVL 4

Expert Comment

by:guramrit
ID: 36495008
you can use two ways to configure client side, through configuration file (app.config), or through coding.
using app.config:
Add app.config in project file, or create <exename>.exe.config parallal to executable path. app.config is equivalant to web.config for Windows applications.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<system.serviceModel>
		<bindings>
			<basicHttpBinding>
				<binding name="basicHttp"
								 allowCookies="true"
								 maxReceivedMessageSize="20000000"
								 maxBufferSize="20000000"
								 maxBufferPoolSize="20000000">
					<readerQuotas maxDepth="32"
												maxArrayLength="200000000"
												maxStringContentLength="200000000"/>
				</binding>
			</basicHttpBinding>
		</bindings>
		<client>
			<endpoint address="http://localhost/TestWcf.svc"
								binding="basicHttpBinding"
								bindingConfiguration="basicHttp"
								contract="ITestWcf"
								name="BasicHttpBinding_ITestWcf">

			</endpoint>
		</client>
		<diagnostics wmiProviderEnabled="true" />
	</system.serviceModel>
</configuration>

Open in new window

using code:
Use following code to initialize service, change your code accordingly.
 
Dim binding As New BasicHttpBinding(BasicHttpSecurityMode.None)
binding.MaxBufferSize = GigaByte
binding.MaxReceivedMessageSize = GigaByte
binding.SendTimeout = TimeSpan.MaxValue
binding.ReceiveTimeout = TimeSpan.MaxValue
binding.OpenTimeout = TimeSpan.FromDays(1)
binding.CloseTimeout = TimeSpan.FromDays(1)
Dim endpoint as new EndpointAddress("http://localhost/TestWcf.svc")

Dim svcClient as new TestWcfClient(binding, endpoint)
svcClient.TestMethod()

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now