Reputation: 4498
I have an issue with sending a large xml from a client to WCF net.tcp service and the client on certain machines throws an out of memory exception when the method is invoked which I'm unable to reproduce on my local machine: Exception Message: Failed to allocate a managed memory buffer of 33554432 bytes. The amount of available memory may be low.
So upon reading ways to resolve this, it seams streaming was the way to go. So I changed the binding on both the client and service accordingly:
<netTcpBinding>
<binding name="NetTcpBinding_IPricerDataService" closeTimeout="00:10:00" transferMode="Streamed"
openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</netTcpBinding>
However, I was under the impression that this meant also changing the service method signatures to take a stream parameter: http://msdn.microsoft.com/en-us/library/ms789010(v=vs.110).aspx
I haven't done this, I have left the method signatures as they were originally but my client still can invoke the service method as per before and it all works as expected.
Does this mean the streaming transformode is not being used as expected or do I not need to change the method signatures to support streaming? Any ideas how I can really check?
Upvotes: 2
Views: 1339
Reputation: 3833
If you don't change your method signatures, you aren't strictly streaming the data, but instead are sending it exactly as you were before, regardless of server configuration. As the MSDN documentation you linked states:
This means, that, for your upstream method, you would specify a Stream
as the parameter, which represents the data you are sending up the stream, and for your downstream method you specify Stream
as the return type, which will contain the data to be read.
This is demonstrated in the following ServiceContract
:
[OperationContract]
Stream GetStream(string data);
[OperationContract]
bool UploadStream(Stream stream);
[OperationContract]
If you do not specify your methods as demonstrated above, you will not end up streaming your data between the client and the service - you'll be using the exact same method as you were before you changed the server config. That's also the reason why your methods still work, even though you specified you want to use streaming in the configuration, but didn't change your methods.
Change those methods to fit the criteria laid out in the MSDN article, and you should be streaming your data properly. Just make sure you take the whole up/down stream thing into account, as it'll be reversed for the client and the server.
On a side note, your exception message:
Exception Message: Failed to allocate a managed memory buffer of 33554432 bytes. The amount of available memory may be low.
Indicates that the system can't allocate 32MB of data for the underlying buffer containing your data. This problem could continue to exist even if you implement streaming properly. 32MB buffers shouldn't be a problem under normal circumstances.
Upvotes: 2