我已经创建了一个用于上传图片的WCF服务,它接受System.IO.Stream
作为输入参数并使用流式传输。当我在Silverlight项目中添加服务引用时,它会自动将我的WCF方法的参数从System.IO.Stream
更改为byte[]
。任何人都可以建议是否有办法解决这个问题,以便我可以获得System.IO.Stream
类型而不是byte[]
。
提前致谢
答案 0 :(得分:2)
Silverlight不支持流式传输模式:http://forums.silverlight.net/forums/t/119340.aspx
所以我认为你很难得到一个字节数组。
答案 1 :(得分:1)
我认为您应该将transferMode
的{{1}}属性设置为正确的值,如this article中所述。然后再次将服务引用添加到Silverlight应用程序中。
答案 2 :(得分:1)
您能否确认您没有点击该服务中的某个读者配额?您可以尝试增加所有这些以查看是否可以解决您的问题。
答案 3 :(得分:0)
即使我正在努力解决同样的问题。最后我自己找到了解决方案。你所能做的就是:
例如。在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.
}
答案 4 :(得分:0)