POSTing multipart / form-data to WCF REST service: action changes

I have a WCF Rest service:

[WebHelp(Comment = "Sample description for GetData")] [WebInvoke(Method="POST", UriTemplate = "invoke", BodyStyle =WebMessageBodyStyle.Bare)] [OperationContract] public string GetData( Stream input) { long incomingLength = WebOperationContext.Current.IncomingRequest.ContentLength; string[] result = new string[incomingLength]; int cnter = 0; int arrayVal = -1; do { if (arrayVal != -1) result[cnter++] = Convert.ToChar(arrayVal).ToString(); arrayVal = input.ReadByte(); } while (arrayVal != -1); return incomingLength.ToString(); } 

I want to upload files (well, a file, one at a time). Using this form to verify:

  <form method="post" action="Service.svc/invoke" > <input type="file" name="aFile" /> </form> <input type="button" onclick="document.forms[0].submit();" /> 

I see that the service receives data, even if using the enctype of the form specified as "multipart / form-data", you get only the name of the element and the name of the downloaded file. However, if I ask enctype, I get nothing; service never gets. I took a break in the code to see what was happening and it was never reached. Do I need to do something special in the URITemplate attribute for enctype "multipart / form-data"? What else am I missing? To hell with this, I used Fiddler to see what was sent to the service with each option, and there was nothing sinister about it.

Without 'multipart / form-data':

 POST /Service4/Service.svc/invoke HTTP/1.1 Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* Referer: <my machine>/Service4/form.htm Accept-Language: en-US User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8; .NET CLR 1.1.4322) Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: okrd14144 Content-Length: 89 Connection: Keep-Alive Pragma: no-cache 

FROM

 POST /Service4/Service.svc/invoke HTTP/1.1 Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */* Referer: <my machine>/Service4/form.htm Accept-Language: en-US User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8; .NET CLR 1.1.4322) Content-Type: multipart/form-data; boundary=---------------------------7da1ce3aa0bd0 Accept-Encoding: gzip, deflate Host: okrd14144 Content-Length: 150119 Connection: Keep-Alive Pragma: no-cache 

I have no ideas

0
c # rest wcf
source share
3 answers

Have you seen this question? WCF service for receiving encrypted messages / form data

0
source share

The change must be done in web.config ...

 system.serviceModel > bindings > webHttpBinding > binding > transferMode="Streamed" 
0
source share

I used this code without success. My web service is not being called. I also changed my web.config according to: WCF service to accept data with multi-line form after encoding .

All my other maintenance methods work fine.

0
source share

All Articles