Why am I having so much trouble uploading a file in WCF4?
This has stumped me now for over 4 hours. I can't find a simple example anywhere?
My web application has a WCF Data Service, I would love to be able to just upload an image to a custom operation on that.
Alternatively I have WCF REST TEMPLATE SERVICE that has only a .cs, NO .config to play with and NO .svc file. It does have a route in the global.asax
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("upload", new WebServiceHostFactory(), typeof(UploadService)));
My operation looks like this:
[WebInvoke(Method ="POST", UriTemplate = "update-pic/{id}")]
public Message UploadPic(string id, Stream fileContents)
{
System.Drawing.Image.FromStream(fileContents).Save(string.Format("{0:ddmmss}.jpg"));
return WebOperationContext.Current.CreateTextResponse("Success: " + id);
}
But no matter what I do on the client, when I call the service I get a 400 response. I could facing prob开发者_如何学运维lems with message size limits, but I don't know how to configure this with the WCF RestTemplate style.
If I do not set the anything to the response stream, then I manage to hit the service.
Does anyone have an end to end service and client example for WCF4 - I'm not interested in 3.5
精彩评论