Solved

C# Web Service using SOAP and maximum request size

Posted on 2011-09-07
7
1,804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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