I have a service interface with a method that has a parameter of type Stream
. Should i close the stream after i have read all data from this stream or is this done by the WCF Runtime when the method call is completed?
The most examples i have seen, do only read the data from the stream, but do not call Close or Dispose on the Stream.
Normally i would say i do not have to close the stream cause the class is not the owner of the stream, but the reason is why is ask this question is that we are currently investigating a problem in our system, that some Android Clients, that use HTTP-Post to send data to this service sometimes have open connections that aren´t closed (Analyzed with netstat
which list ESTABLISHED Tcp connections).
[ServiceContract]
public interface IStreamedService {
[OperationContract]
[WebInvoke]
Stream PullMessage(Stream incomingStream);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false)]
public class MyService : IStreamedService {
public System.IO.Stream PullMessage(System.IO.Stream incomingStream) {
// using(incomingStream) {
// Read data from stream
// }
Stream outgoingStream = // assigned by omitted code;
return outgoingStream;
}
Configuration of the Service/Binding
<webHttpBinding>
<binding name="WebHttpBindingConfiguration"
transferMode="Streamed"
maxReceivedMessageSize="1048576"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
closeTimeout="00:10:00"/>
</webHttpBinding>