?
Solved

C# Web Service using SOAP and maximum request size

Posted on 2011-09-07
7
Medium Priority
?
2,121 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 

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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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