WCF REST File upload with additional parameters
I have been trying fruitlessly to try and create a simple REST file upload WCF Service, which accepts more than one piece of information.
I have found a fair few places on the Internet that suggest that it is possible to have more than one parameter to a OperationContract that has a Stream as one of the parameters (Upload file with REST, Using Silverlight and WCF to create a RESTful File Upload Utility, WCF REST File Upload, Uploading File to server from ASP.Net client using WCF REST Service, etc.) but no matter how many times I try I always get the same error message.
For request in operatio开发者_JAVA百科n Upload to be a stream the operation must have a single parameter whose type is Stream.
Is it actually possible to have an OperationContract that accepts more than one parameter when one of them is a Stream? If so are there any particular steps that need to be taken which I may have missed that would have caused for me not to be able to do so.
For reference I am using Visual Studio 2010, WCF 4.0
I have uploaded the example project that I am trying to get to work, its literally the minimum of what going by the examples I have read that I should need to be able to upload a file with additional parameters. My Example.
Yes, it is possible. I am doing it with UriTemplates.
[WebGet(UriTemplate="ReceiveChunk/{complete}?offset={offset}", Method ="POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public string ReceiveChunk(string complete, int offset, Stream fileContents)
{
//implementation
}
Is that what you're looking for?
I know this is an old question but I've been struggling with this today. I finally found this link, specifically:
2. You are not using WebEndpoint or WebServiceHost;
I was self hosting my service in a console app and was using ServiceHost not WebServiceHost. Changing the host type resolved my issue and explained my confusion. SOAP WCF services require the operation to have a single Stream parameter only, REST WCF services don't.
精彩评论