Click here to Skip to main content
13,249,174 members (32,226 online)
Rate this:
 
Please Sign up or sign in to vote.
I am trying to send image through wcf from my windows application,

See my sample code below:

Windows code:

private void BtnRegister_Click(object sender, EventArgs e)
       {
           FileStream fs;
           byte[] imgByteArrFriends;
           RetunImageBytes(PathFriends, out fs, out imgByteArrFriends);
 
           byte[] imgByteArrFamily;
           RetunImageBytes(PathFamily, out fs, out imgByteArrFamily);
 
           byte[] imgByteArrLovers;
           RetunImageBytes(PathLovers, out fs, out imgByteArrLovers);
 
           byte[] imgByteArrOthers;
           RetunImageBytes(PathOthers, out fs, out imgByteArrOthers);
 
           string StatusMessage=ObjProfilePicture.SaveProfilePictures("Eswar", imgByteArrFriends, imgByteArrLovers, imgByteArrFamily, imgByteArrOthers);
       }
 
       private void RetunImageBytes(string path,out FileStream fs, out byte[] imgByteArr)
       {
           imgByteArr = null;
           fs = null;
           if (path != null)
           {
               fs = new FileStream(path, FileMode.Open, FileAccess.Read);
               imgByteArr = new byte[fs.Length];
               fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));
               fs.Close();
           }
       }





WCF Code:

[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
   public string SaveProfilePictures(string UserID, byte[] Friends, byte[] Lovers, byte[] Family, byte[] Others)
   {
       string Message = null;
       try
       {
           objBlobDbConfig.ExecuteCommand(UserID, Friends, Lovers, Family, Others);
           Message="Success";
       }
       catch (Exception ex)
       {
           Message= "Image Upload Failed.. Please try after sometime";
       }



If any body know the solution please help me

What I have tried:

I am trying to send image through wcf from my windows application,

See my sample code below:

Windows code:

private void BtnRegister_Click(object sender, EventArgs e)
       {
           FileStream fs;
           byte[] imgByteArrFriends;
           RetunImageBytes(PathFriends, out fs, out imgByteArrFriends);
 
           byte[] imgByteArrFamily;
           RetunImageBytes(PathFamily, out fs, out imgByteArrFamily);
 
           byte[] imgByteArrLovers;
           RetunImageBytes(PathLovers, out fs, out imgByteArrLovers);
 
           byte[] imgByteArrOthers;
           RetunImageBytes(PathOthers, out fs, out imgByteArrOthers);
 
           string StatusMessage=ObjProfilePicture.SaveProfilePictures("Eswar", imgByteArrFriends, imgByteArrLovers, imgByteArrFamily, imgByteArrOthers);
       }
 
       private void RetunImageBytes(string path,out FileStream fs, out byte[] imgByteArr)
       {
           imgByteArr = null;
           fs = null;
           if (path != null)
           {
               fs = new FileStream(path, FileMode.Open, FileAccess.Read);
               imgByteArr = new byte[fs.Length];
               fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));
               fs.Close();
           }
       }





WCF Code:

[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
   public string SaveProfilePictures(string UserID, byte[] Friends, byte[] Lovers, byte[] Family, byte[] Others)
   {
       string Message = null;
       try
       {
           objBlobDbConfig.ExecuteCommand(UserID, Friends, Lovers, Family, Others);
           Message="Success";
       }
       catch (Exception ex)
       {
           Message= "Image Upload Failed.. Please try after sometime";
       }



If any body know the solution please help me
Posted 7-Apr-16 8:36am
Updated 7-Apr-16 9:08am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));

Why are you trying to convert an integer into an integer? You will end up with an invalid number and thus not read all the data.

See FileStream.Length Property (System.IO)[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 7 Apr 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100