I am working on a WCF project that generates and returns a pdf file as System.IO.Stream. I have come across a behavior that I cannot explain.
One of the methods exposed by the WCF is as follows:
Public Function Print(ByVal input As Integer) As Stream
'Do stuff here.
Return pdfStream
End Function
The client calls the method with:
Dim streamReturn as Stream
streamReturn = Service.Print(input)
This works great. The problem arose when I tried to change the data type of input to String.
Public Function Print(ByVal input As String) As Stream
'Do stuff here.
Return pdfStream
End Function
When I updated the Service Reference in the Client, an error is now listed for:
streamReturn = Service.Print(input)
“Value of type ‘1-dimensional array of Byte’ cannot be converted to ‘System.IO.Stream’.”
It appears as though when the data type of my input is changed to String, the transfer mode reverts from streamed back to buffered. Any ideas why?
EDIT: The WCF is in .Net 4.0, the Client is .Net 3.5
I found a solution. It was due to the serialization method I was using. I had added XMLSerializerFormat() to my ServiceContract so I could use an indexed List inside one of my custom objects. Object was:
Once I removed the XMLSerializerFormat() tag (Reverting to DataContractFormat) I had to remove the DataMember() tag from the indexed property, then was able to have a String parameter and Stream return.