By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

unable to send Byte[] from webform client project to web api service project using c#

P: 1
I have c# webForm clientproject and web api service project.

I'm sending one file from c# webForm clientproject to web api service project using Byte[] but at web api service project I'm getting null as Byte[]

Expand|Select|Wrap|Line Numbers
  1. winform c# project code
  2.  
  3.     private void button1_Click(object sender, System.EventArgs e)
  4.     {
  5.         FileStream objfilestream = new FileStream("C:\\mytext.dll",FileMode.Open,FileAccess.Read);
  6.         int len = (int)objfilestream.Length;
  7.         Byte[] mybytearray = new Byte[len];
  8.         objfilestream.Read(mybytearray,0,len);
  9. // call service using REST SHARP        
  10. var restClient = new RestClient("http://localhost:51737/");
  11.             RestSharp.RestRequest restRequest = new RestRequest("api/values", Method.GET);
  12.             restRequest.AddParameter("docbinaryarray", mybytearray);
  13.             restRequest.AddParameter("docname", sFile.Remove(0, sFile.LastIndexOf("\\") + 1)); 
  14.             restRequest.AddHeader("header", "value");
  15.             RestSharp.IRestResponse restResponse = restClient.Execute(restRequest);
  16.         objfilestream.Close();
  17.     }
  18. Now in web api service
  19.  
  20. // GET api/values
  21.         public IEnumerable<string> Get(Byte[] docbinaryarray, string docname)
  22.         {
  23.             string strdocPath;
  24.             strdocPath = @"C:\Users\ServicetEst\bin" + docname;
  25.             FileStream objfilestream = new FileStream(strdocPath, FileMode.Create, FileAccess.ReadWrite);
  26.             objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length);
  27.             objfilestream.Close();
  28.             return "";
  29.         }
  30.  
But inside web api service i'm getting NULL for docbinaryarray why so any clue? basically i'm sending one dll file from one solution to another solution using Byte[]
Jan 21 '16 #1
Share this Question
Share on Google+
1 Reply


100+
P: 293
Is your file stream byte[] public or make sure it is serializable ?

Hope this helps.
Jan 31 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.