locked
Unable to POST large files to WCF REST Service. RRS feed

  • Question

  • User-431888895 posted

    My requrirement is to Upload large files  from Client to WCF REST service. Am able to upload small size image(8.3kb) successfully. when trying to upload larger files say (16kb or more) I am receiveing an error. "The remote server returned an error :(400) Bad Request".

    In Server side Web config i used webHttpBinding.

    <webHttpBinding>
    <binding name="web" maxReceiveMessagesize="250000000" maxBufferSize="250000000" maxBufferPoolSize="250000000" closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeOut="00:10:00">

    <readerQuotas maxDepth="250000000" maxStringContentLeangth="250000000" maxArraylength="250000000" maxBytesPerread="250000000"
    maxNameTableCharCount="250000000"/>
    <security mode="None" />
    </binding>
    </webHttpBinding>

    <security>
    <requestFiltering>
    <requestLimits maxAllowedContentLength="52428800" />
    </requestFiltering>
    </security>

    Iservice1.cs:

    [OperationContract]
    [WebInvoke(UriTemplate = "/UplaodImage", Method = "POST",RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Imageupload GetImageUpload( Imageupload images);

    public class Imageupload
    {
    [DataMember]
    public string imgName{get; set;}


    [DataMember]
    public byte[] img{get; set;}

    }

    In service1.cs

    public Imageupload GetImageUpload( Imageupload images)

    {

    // upload functionality
    }

    From Client: In ButtonClick event :

    byte[] newImg= File.ReadAllBytes(@"D:\temp\img.png")
    Imageupload images = new Imageupload {imgName ="img.png",img =newImg};

    WebClient Proxy1 = new WebClient();
    Proxy1.Headers["Content-type"] = "application/json";
    MemoryStream ms = new MemoryStream();
    DataContractJsonSerializer sezToUplaod = new DataContractJsonSerializer(typeof(Imageupload));

    sezToUplaod .WriteObject(ms, Imageupload);
    byte[] responceData = Proxy1.UploadData(http://localhost:XXXX/Service1.svc/UplaodImage", "POST", ms.ToArray());
    Stream stream = new MemoryStream(responceData);

    DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(Imageupload));

    Thanks in advance..

    Tuesday, August 27, 2013 5:54 AM

Answers

  • User-431888895 posted

    I found the answer. I was missing bindingConfiguration="web" in <endpoint> section. 

    Thank You.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2013 7:07 AM

All replies

  • User289622470 posted

    Hi,

      Can you provide the code you have written side your rest method GetImageUpload

    Thanks,

    Tuesday, August 27, 2013 8:32 AM
  • User-431888895 posted

    here is my code in GetImageUpload method

    Public Imageupload GetImageUpload( Imageupload images)

    {

    // upload function

    byte[] newimage=images.img;

    System.Drawing.Image myImage;

    string strFileName=@"d:\"+"myImage.png";

    if(newimage != null)

    {

    using(MemoryStream stream= new MemoryStream(newimage))

    {

    myImage=System.Drawing.Image.FromStream(stream);

    myImage.Save(strFileName);

    }

    images.imgName="Successfully saved";

    }

    else

    {

    images.imgName="No image data found";

    }

    return images;

    }

    Tuesday, August 27, 2013 10:20 AM
  • User-431888895 posted

    I found the answer. I was missing bindingConfiguration="web" in <endpoint> section. 

    Thank You.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2013 7:07 AM