I have a File i want to upload to a Webservice, but it needs additional params, so I create some hidden fields with the associated name:value pairs to get pushed to the serv
If the string
result parameter on your NewImage
method is some kind of unique identifier, you could create a second method called something like NewImageAttributes
which accepts the extra data, along with the unique identifier, and then you could tie the data together again in your service.
Of course, this would mean two calls to the service, but it may solve your issue.
When you send a stream, it will actually send everything in the request. I did this to get the data:
public string NewImage(Stream data){
NameValueCollection PostParameters = HttpUtility.ParseQueryString(new StreamReader(data).ReadToEnd());
string server = PostParameters["server"],
string datasource = PostParameters["datasource"],
string document = PostParameters["document"];
string image_id = PostParameters["image_id"];
var img = PostParameters["File"];
//do other processing...
}
This post: How to: Create a Service That Accepts Arbitrary Data using the WCF REST Programming Model describes another method of posting a stream along with some data.
They show how to send the file name (but you can add and/or replace that with any string parameter) along with the file.
The contract is:
[ServiceContract]
public interface IReceiveData
{
[WebInvoke(UriTemplate = "UploadFile/{strParam1}/{strParam2}")]
void UploadFile(string strParam1, string strParam2, Stream fileContents);
}
The exposed service will accept the stream via POST along with the parameters that were defined.
It's an issue\bug with WCF, which don't accept any other parameters when using Stream input.
We also had similar issue with WCF and after all research we decided to convert other input parameters also into stream and attach it to the input with some delimter
How about using HttpRequest.QueryString[]
?
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "NewImage")]
string NewImage(Stream data);
you call it through the URL like:
\NewImage?server={server}&datasource={datasource}&document={doc}&image_id={id}
Then in your code:
public string NewImage(Stream imgStream)
{
var request = System.Web.HttpContext.Current.Request;
var server= request.QueryString["server"];
var datasource = request.QueryString["datasource"];
var document= request.QueryString["document"];
var image_id= request.QueryString["image_id"];
...
}
I'd been looking for something like this for a while, and just stumbled across it today.
Just a thought - how about using HTTP headers? You can then process using WebOperationContext.IncomingRequest.