I'm writting a WCF Rest service. He would be use to receive and save a picture. I take and send the picture with a windows phone 7 client. I can send the picture who is parse on a stream (in the service side) but the picture won't be save because of a "badparameter".
Code use to take the picture :
private void TakePictureAction()
{
//Show the camera
_camera.Show();
//Append when camera task finished.
_camera.Completed += delegate(object sender, PhotoResult e)
{
_photoImage = new BitmapImage();
_photoImage.SetSource(e.ChosenPhoto);
};
}
Code use to send the picture (with rest sharp):
var client = new RestClient("http://127.0.0.1:81/Service.svc");
var request = new RestRequest("/uploadImage", Method.POST);
request.AddBody(_photoImage);
try
{
client.ExecuteAsync(request, response =>
{
//Do stuff
});
}
catch (Exception ex)
{
MessageBox.Show("error");
}
And code on the serveur side :
public void UploadImage(Stream fileStream)
{
if (fileStream != null)
{
string filePath = @"c:\";
using (FileStream fileToUpload = new FileStream(filePath + "ok.bmp", FileMode.Create))
{
byte[] byteArray = new byte[10000];
int bytesRead = 0;
do
{
bytesRead = fileStream.Read(byteArray, 0, byteArray.Length);
if (bytesRead > 0)
{
fileToUpload.Write(byteArray, 0, bytesRead);
}
} while (bytesRead > 0);
using (MemoryStream ms = new MemoryStream(byteArray))
{
Bitmap img = (Bitmap)Image.FromStream(ms);
img.Save(@"c:\img.bmp");
}
}
}
}
My Service method
[OperationContract]
[WebInvoke(UriTemplate = "/uploadImage", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
void UploadImage(Stream img);
Where am I wrong ?