Reputation: 823
Getting error while browsing the .svc file of service. InvalidOperationException: For request in operation MethodName to be a stream the operation must have a single parameter whose type is Stream" In service Contract:
[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/upload?filename={filename}&objrid={objrid}")]
string uploadfile(string filename, long objrid, Stream data);`
The compiler is not generating .svc file. Though This operation is working fine. But other methods in that service are not working. How can i resolve this problem?
in web.config: Service tag:
<service behaviorConfiguration="TransferServiceBehavior" name="namespace.Service">
<endpoint address="/Service" behaviorConfiguration="webby" binding="webHttpBinding" contract="namespace.Icontract" />
<endpoint binding="basicHttpBinding" contract="namespace.Icontract" />
</service>
behaviorConfiguration:
<behavior name="TransferServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500"/>
</behavior>
binding cinfig:
This Operation is working fine but other Operation in same service contract is not working: Other Operation:
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "/ProcessViewRequestMobile")]
Stream ProcessDownload();
When i comment first operation the second one works fine. How can i make my both methods working. I have to add both the methods in same service contract. Thanks in advance.
Upvotes: 4
Views: 3886
Reputation: 1918
Well, you are getting this error because the default WCF stream formatter does not support this. You are try. all within the same method. This is just not supported, even if it seemingly works somehow.
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 or a similar custom endpoint, this programming model is actually supported because REST and some other scenarios have their 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. 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.
Upvotes: 1