![](/img/trans.png)
[英]C# POCO to a Stream/Byte[] and process while reading with a Silverlight 4 client over WCF
[英]Silverlight changes the io.Stream to byte[]
我已經創建了一個用於上傳圖像的WCF服務,它接受System.IO.Stream
作為輸入參數並使用流式傳輸。 當我在Silverlight項目中添加服務引用時,它會自動將我的WCF方法的參數從System.IO.Stream
更改為byte[]
。 任何人都可以建議是否有辦法解決這個問題,以便我可以獲得System.IO.Stream
類型而不是byte[]
。
提前致謝
Silverlight不支持流式傳輸模式: http : //forums.silverlight.net/forums/t/119340.aspx
所以我認為你很難得到一個字節數組。
我認為你應該將basicHttpBinding
的transferMode
屬性設置為正確的值,如本文所述 。 然后再次將服務引用添加到Silverlight應用程序。
你能否證實你沒有達到服務中的一個讀者配額? 您可以嘗試增加所有這些以查看是否可以解決您的問題。
即使我在同樣的問題上掙扎。 最后我自己找到了解決方案。 你所能做的就是:
例如。 在WCF方面:
[DataContract]
Class FileInfo
{
[DataMember]
string filename;
[DataMember]
string[] StrArr;
}
接收功能:
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......
.........
}
在客戶端:
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.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.