I have services that return large objects, default transfermode (buffered) doesn't suit to our requirements.
Actually the service is written already and the project team is experiencing out of memory exceptions and slow performance intermittently. Now this needs to be fixed with some patching, rewrting all the services is not an option as the project team is nearing a delivery.
I have an understanding that changing the transfermode to StreamedResponse/Streamed may help in a big way + choosing net.tcp instead of http bindings (intranet application with thick client). I need to know whether I will get benefit for all the operationcontracts or only those, which return Stream/Message.
I created a little sample to check if it has any impact on other return types (DataTable/DataSet) and it seems it effects all the return types including DataTable/DataSet. I checked WCF HttpTransport: streamed vs buffered TransferMode and looks like the same behavior is experienced by others as well.
The only thing missing here is some concrete documentation which clearly states that it effects all the operationcontracts irrespective of return type. I need some references so that I can push my recommendation for this chnage.
Please do not suggest not to return DataTable/DataSet from the services; I know its a bad-bad practice and should be avoided all the times but in this case the services were already there and I can't ask them to change everything at this moment.
Update: My perception is based on following test
My interface
[ServiceContract]
public interface IMediaManager
{
[OperationContract]
Stream Play(int mediaId);
[OperationContract]
DataSet GetJunk();
}
My Implementation
public class MediaManager : IMediaManager
{
public Stream Play(int mediaId)
{
String path = GetMedia(mediaId);
FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read,FileShare.Read);
return fStream;
}
public DataSet GetJunk()
{
return GetLargeJunkDataSet20PlusMegs();
}
}
Hosted over IIS - Non Http WAS, Server Configuration File (Tags stripped off, only relevant ones)
<system.serviceModel>
<services>
<service name="MediaService.MediaManager" behaviorConfiguration="MediaServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9876/MediaService/MediaManager.svc" />
</baseAddresses>
</host>
<endpoint address="" binding="customBinding"
bindingConfiguration="StreamedTcpBinding" name="MediaManagerTcp"
contract="MediaService.IMediaManager" />
<endpoint address="mexTcp" binding="mexTcpBinding" name="mexTcp"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="StreamedTcpBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00">
<binaryMessageEncoding />
<tcpTransport transferMode="Streamed" portSharingEnabled="true" />
</binding>
</customBinding>
</bindings>
Client Configuration File (Only relevant tags)
<binding name="MediaManagerTcp" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647"
***maxBufferSize="1001"*** maxConnections="10" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
If you see above, the maxBufferSize is 1001 bytes, however the actual message would be 20+ mb. This makes me think the Streamed is working for DataSet as well (everything, not only limited to Stream and Message). I hope my interpretation is correct of maxBufferSize (its the maximum size which will be received in one chunk). I must also add that the same method fails if I switch to Buffered mode.
I hope my analysis makes sense, if not clear then please let me know and I shall try again?
I will repeat my question again so that it doesn't get lost :)
The only thing missing here is some concrete documentation which clearly states that it effects all the operationcontracts irrespective of return type. I need some references/experiences so that I can push my recommendation for this chnage.
Any help will be much appreciated!
Thanks,
A