开发者

Silverlight changes the io.Stream to byte[]

I have created a WCF service for uploading image开发者_JAVA百科s , which accepts System.IO.Stream as input parameter and am using streaming. When I added the service reference in Silverlight project then it automatically changed the parameter of my WCF method from System.IO.Stream to byte[]. Can anyone suggest if there is a way around this so that I can get System.IO.Stream type rather than byte[].

Thanks in advance


Silverlight does not support transfer mode streamed: http://forums.silverlight.net/forums/t/119340.aspx

So I think that you are stuck with getting a byte array.


Can you verify that you're not hitting one of the reader quotas in the service? You can try increasing all of them to see if this solves your problem.


I think you should set the transferMode property of your basicHttpBinding to the correct value, as described in this article. And then add the service reference to your Silverlight application again.


http://blogs.msdn.com/b/carlosfigueira/archive/2010/07/08/using-transfermode-streamedresponse-to-download-files-in-silverlight-4.aspx


Even I was struggling with the same issue. At last I got a solution by myself. All you can do is:

  1. declare the accepting parameter as string array in the WCF Service.
  2. convert the byte array into string array at client place.
  3. After Sending the converted byte array as string array again convert back it into byte array.

eg. at the WCF side:

[DataContract]
Class FileInfo  
{
 [DataMember] 
 string filename;
 [DataMember]
 string[] StrArr;
}

the receiving function:

public void uploadFile(FileInfo fi)
{
 int len=fi.StrArr.len;
 byte[] myFileByte=new byte[len];

 for(int i=0;i<len;i++)
 {
  myFileByte[i]=Convert.ToByte(fi.StrArr[i]);
 }
 //your uploaded File buffer is ready as myFileByte
 //proceeding operations are most welcome here......
.........
}

At Client Side:

public void UploadMyFile()
{
 //Take the InputStream from the selected File as iStream;
 int len=(int)iStream.length;
 byte[] buffer=new byte[len];
 string[] MyStrArr=new string[len];

 for(int i=0;i<len;i++)
 {
  MyStrArr[i]=Convert.ToString(buffer[i]);
 } 
  //Here your string array is ready to send to the WCF Service....
  //I m confident this code will work perfectly with some file limitation consideartions. 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜