Wcf File Upload Limit



Encoding files like this grows the size of the file by as much as two thirds in the soap body (ie. A 6 MB file becomes a 9 MB file over the wire). It's likely that your 25 MB upload is turning into HUGE soap envelopes. I'd strongly suggest reading this. Which might get you into DIME. The MaxBufferSize property is required to constrain the memory that WCF buffers. It is important to set this to a safe value (or keep it at the default value) when streaming. For example, suppose your service must receive files up to 4 GB in size and store them on the local disk.

-->

This topic discusses new features that make writing WCF applications simpler.

Simplified Generated Configuration Files

File upload among us

File Upload Sites

When you add a service reference in Visual Studio or use the SvcUtil.exe tool a client configuration file is generated. In previous versions of WCF these configuration files contained the value of every binding property even if its value is the default value. In WCF 4.5 the generated configuration files contain only those binding properties that are set to a non-default value.

The following is an example of a configuration file generated by WCF 3.0.

The following is an example of the same configuration file generated by WCF 4.5.

Contract-First Development

WCF now has support for contract-first development. The svcutil.exe tool has a /serviceContract switch which allows you to generate service and data contracts from a WSDL document.

Add Service Reference From a Portable Subset Project

Portable subset projects enable .NET assembly programmers to maintain a single source tree and build system while still supporting multiple .NET implementations (desktop, Silverlight, Windows Phone, and Xbox). Portable subset projects only reference .NET portable libraries that are assemblies that can be used on any .NET implementation. The developer experience is the same as adding a service reference within any other WCF client application. For more information, see Add Service Reference in a Portable Subset Project.

ASP.NET Compatibility Mode Default Changed

WCF provides ASP.NET compatibility mode to grant developers full access to the features in the ASP.NET HTTP pipeline when writing WCF services. To use this mode, you must set the aspNetCompatibilityEnabled attribute to true in the <serviceHostingEnvironment> section of web.config. Additionally, any service in this appDomain needs to have the RequirementsMode property on its AspNetCompatibilityRequirementsAttribute set to Allowed or Required. By default AspNetCompatibilityRequirementsAttribute is now set to Allowed and the default WCF service application template sets the aspNetCompatibilityEnabled attribute to true. For more information, see What's New in Windows Communication Foundation 4.5 and WCF Services and ASP.NET.

Streaming Improvements

  • New support for asynchronous streaming has been added to WCF. To enable asynchronous streaming, add the DispatcherSynchronizationBehavior endpoint behavior to the service host and set its AsynchronousSendEnabled property to true. This can benefit scalability when a service is sending streamed messages to multiple clients which are reading slowly. WCF does not block one thread per client anymore and will free up the thread to service another client.

  • Removed limitations around buffering of messages when a service is IIS hosted. In previous versions of WCF when receiving a message for an IIS-hosted service that used streaming message transfer, ASP.NET would buffer the entire message before sending it to WCF. This would cause large memory consumption. This buffering has been removed in .NET Framework 4.5 and now IIS-hosted WCF services can start processing the incoming stream before the entire message has been received, thereby enabling true streaming. This allows WCF to respond immediately to messages and allows improved performance. In addition, you no longer have to specify a value for maxRequestLength, the ASP.NET size limit on incoming requests. If this property is set, it is ignored. For more information about maxRequestLength see <httpRuntime> configuration element. You will still need to configure the maxAllowedContentLength, For more information, see IIS Request Limits.

New Transport Default Values

The following table describes the settings that have changed and where to find additional information.

PropertyOnNew DefaultMore Information
channelInitializationTimeoutNetTcpBinding30 secondsThis property determines how long a TCP connection can take to authenticate itself using the .NET Framing protocol. A client needs to send some initial data before the server has enough information to perform authentication. This timeout is intentionally made smaller than the ReceiveTimeout (10 min) so that malicious unauthenticated clients do not keep the connections tied up to the server for long. The default value is 30 seconds. For more information about ChannelInitializationTimeout
listenBacklogNetTcpBinding16 * number of processorsThis socket-level property describes the number of 'pending accept' requests to be queued. If the listen backlog queue fills up, new socket requests will be rejected. For more information about ListenBacklog
maxPendingAcceptsConnectionOrientedTransportBindingElement
SMSvcHost.exe
2 * number of processors for transport
4 * number of processors for SMSvcHost.exe
This property limits the number of channels that the server can have waiting on a listener. When MaxPendingAccepts is too low, there will be a small interval of time in which all of the waiting channels have started servicing connections, but no new channels have begun listening. A connection can arrive during this interval and will fail because nothing is waiting for it on the server. This property can be configured by setting the MaxPendingConnections property to a larger number. For more information, see MaxPendingAccepts and Configuring the Net.TCP Port Sharing Service
maxPendingConnectionsConnectionOrientedTransportBindingElement12 * number of processorsThis property controls how many connections a transport has accepted but have not been picked up by the ServiceModel Dispatcher. To set this value, use MaxConnections on the binding or maxOutboundConnectionsPerEndpoint on the binding element. For more information about MaxPendingConnections
receiveTimeoutSMSvcHost.exe30 secondsThis property specifies the timeout for reading the TCP framing data and performing connection dispatching from the underlying connections. This exists to put a cap on the amount of time SMSvcHost.exe service is kept engaged to read the preamble data from an incoming connection. For more information, see Configuring the Net.TCP Port Sharing Service.

Note

These new defaults are used only if you deploy the WCF service on a machine with .NET Framework 4.5. If you deploy the same service on a machine with .NET Framework 4.0, then the .NET Framework 4.0 defaults are used. In such cases it is recommended to configure these settings explicitly.

XmlDictionaryReaderQuotas

XmlDictionaryReaderQuotas contains configurable quota values for XML dictionary readers which limit the amount of memory utilized by an encoder while creating a message. While these quotas are configurable, the default values have changed to lessen the possibility that a developer will need to set them explicitly. MaxReceivedMessageSize quota has not been changed so that it can still limit memory consumption preventing the need for you to deal with the complexity of the XmlDictionaryReaderQuotas. The following table shows the quotas, their new default values and a brief explanation of what each quota is used for.

Quota NameDefault ValueDescription
MaxArrayLengthInt32.MaxValueGets and sets the maximum allowed array length. This quota limits the maximum size of an array of primitives that the XML reader returns, including byte arrays. This quota does not limit memory consumption in the XML reader itself, but in whatever component that is using the reader. For example, when the DataContractSerializer uses a reader secured with MaxArrayLength, it does not deserialize byte arrays larger than this quota.
MaxBytesPerReadInt32.MaxValueGets and sets the maximum allowed bytes returned for each read. This quota limits the number of bytes that are read in a single Read operation when reading the element start tag and its attributes. (In non-streamed cases, the element name itself is not counted against the quota). Having too many XML attributes may use up disproportionate processing time because attribute names have to be checked for uniqueness. MaxBytesPerRead mitigates this threat.
MaxDepth128 nodes deepThis quota limits the maximum nesting depth of XML elements. MaxDepth interacts with MaxBytesPerRead: the reader always keeps data in memory for the current element and all of its ancestors, so the maximum memory consumption of the reader is proportional to the product of these two settings. When deserializing a deeply-nested object graph, the deserializer is forced to access the entire stack and throw an unrecoverable StackOverflowException. A direct correlation exists between XML nesting and object nesting for both the DataContractSerializer and the XmlSerializer. MaxDepth is used to mitigate this threat.
MaxNameTableCharCountInt32.MaxValueThis quota limits the maximum number of characters allowed in a nametable. The nametable contains certain strings (such as namespaces and prefixes) that are encountered when processing an XML document. As these strings are buffered in memory, this quota is used to prevent excessive buffering when streaming is expected.
MaxStringContentLengthInt32.MaxValueThis quota limits the maximum string size that the XML reader returns. This quota does not limit memory consumption in the XML reader itself, but in the component that is using the reader. For example, when the DataContractSerializer uses a reader secured with MaxStringContentLength, it does not deserialize strings larger than this quota.

Important

Refer to 'Using XML Safely' under Security Considerations for Data for more information about securing your data.

Note

These new defaults are used only if you deploy the WCF service on a machine with .NET Framework 4.5. If you deploy the same service on a machine with .NET Framework 4.0, then the .NET Framework 4.0 defaults are used. In such cases it is recommended to configure these settings explicitly.

WCF Configuration Validation

Limit

As part of the build process within Visual Studio, WCF configuration files are now validated. A list of validation errors or warnings are displayed in Visual Studio if the validation fails.

XML Editor Tooltips

File Upload Free

In order to help new and existing WCF service developers to configure their services, the Visual Studio XML editor now provides tooltips for every configuration element and its properties that is part of the service configuration file.

Wcf File Upload Limit File

BasicHttpBinding Improvements

Wcf File Upload Limit Password

  1. Enables a single WCF endpoint to respond to different authentication modes.

  2. Enables a WCF service’s security settings to be controlled by IIS