Solved

C# Web Service using SOAP and maximum request size

Posted on 2011-09-07
7
1,561 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:ChrisMDrew
Comment Utility
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
Comment Utility
Chris - if you're using WinForms app you should have app.config - change message size there.
0
 

Author Closing Comment

by:ChrisMDrew
Comment Utility
Thanks - that seems to be working...
0
 
LVL 4

Expert Comment

by:guramrit
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

14 Experts available now in Live!

Get 1:1 Help Now