如何将图像或视频从Windows应用程序发送到WCF
问题描述:
我正试图从我的Windows应用程序通过wcf发送图像,
请参阅下面的示例代码:
Windows代码:
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代码:
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";
}
如果有人知道解决方案请帮帮我
我尝试了什么:
我试图通过wcf从我的窗户发送图像应用程序,
请参阅下面的示例代码:
Windows代码:
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代码:
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
答
fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));
为什么要尝试将整数转换为整数?您最终会得到一个无效的数字,因此无法读取所有数据。
请参阅 FileStream.Length Property(System.IO) [ ^ ]。