How to solve System.InvalidOperationException: For request in operation Test to be a stream the operation must have a single parameter whose type is Stream

 You are getting this error because the default WCF stream formatter does not support this. You are probably trying to upload some file stream and transfer some other parameters, such as file name, etc within the same method. For example,


void Test(string fileName, Stream fileContent);

If this is not a REST endpoint, you can work around this issue by using MessageContract wrapping the multiple parameters into one class.

If this is a REST endpoint, this programming model is actually supported because REST has its own formatter which handles multiple parameters correctly. However, if you continue to see this issue, then please make sure your WebHttpBehavior is set up correctly. Possible reason for not having that behavior set up correctly could be:

1. You are using a custom behavior, and its endpoint does not have the correct the contract name matching with the WCF contract;

2. You are not using WebEndpoint or WebServiceHost;

You can also workaround this issue by choosing Buffered option in the TransferMode on the binding. But that seems to be defeating the whole purpose of the Streaming.

Comments (0)

Skip to main content