Solved

C# Web Service using SOAP and maximum request size

Posted on 2011-09-07
7
1,733 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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