I have a WCF service which is returning PDF files as a stream over a NetTcp endpoint. This is all working fine. However, if the file is not found, or if I can’t find the related row in the database to retrieve the filepath then I return Stream.Null from the service.
However I can’t seem to find a way to compare the returning stream to check and see if it is empty or not.
I have tried the following:
If myStream IsNot Stream.Null
'Code to execute if stream isn't empty
End If
and
If Not streamPDF.Equals(Stream.Null)
'Code to execute if stream isn't empty
End If
But neither of these work as the code just carries on into the If block.
Any thoughts?
The
Stream.Nullis only your service scoped construct. For client you will get most probably empty stream => it will be same stream type as if you really send data.It is strange design choice. If file doesn’t exists it is “expected” exception and it should be handled with
FaultContractand typedFaultException.