Wcf Silverlight将io.Stream更改为字节[]

Wcf Silverlight将io.Stream更改为字节[],wcf,silverlight-3.0,Wcf,Silverlight 3.0,我创建了一个用于上传图像的WCF服务,它接受System.IO.Stream作为输入参数,并使用流媒体。当我在Silverlight项目中添加服务引用时,它会自动将WCF方法的参数从System.IO.Stream更改为byte[]。有没有人能建议是否有办法解决这个问题,这样我就可以得到System.IO.Stream类型而不是byte[] 提前感谢我认为您应该将basicHttpBinding的transferMode属性设置为正确的值,如中所述。然后再次将服务引用添加到Silverlight

我创建了一个用于上传图像的WCF服务,它接受System.IO.Stream作为输入参数,并使用流媒体。当我在Silverlight项目中添加服务引用时,它会自动将WCF方法的参数从System.IO.Stream更改为byte[]。有没有人能建议是否有办法解决这个问题,这样我就可以得到System.IO.Stream类型而不是byte[]


提前感谢

我认为您应该将basicHttpBinding的transferMode属性设置为正确的值,如中所述。然后再次将服务引用添加到Silverlight应用程序。

我认为您应该将basicHttpBinding的transferMode属性设置为正确的值,如中所述。然后再次将服务引用添加到Silverlight应用程序。

Silverlight不支持传输流模式:


因此,我认为您必须获得字节数组。

Silverlight不支持传输模式流式传输:


因此,我认为您必须获得一个字节数组。

能否验证您没有达到服务中的某个读卡器配额?您可以尝试增加所有的读卡器配额,看看这是否解决了您的问题。

您能否验证您没有达到服务中的某个读卡器配额?您可以尝试增加所有这些值,看看这是否解决了您的问题。

即使是我也在为同样的问题而挣扎。最后我自己找到了解决办法。你所能做的就是:

在WCF服务中将接受参数声明为字符串数组。 在客户端将字节数组转换为字符串数组。 将转换后的字节数组作为字符串数组发送后,再次将其转换回字节数组。 例如,在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. 
}

就连我也在为同样的问题挣扎。最后我自己找到了解决办法。你所能做的就是:

在WCF服务中将接受参数声明为字符串数组。 在客户端将字节数组转换为字符串数组。 将转换后的字节数组作为字符串数组发送后,再次将其转换回字节数组。 例如,在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. 
}

谢谢你的回复!我已经将该属性设置为流。当我在Windows项目中添加此服务引用时,它显示IO.Stream,但当我在silverlight项目中添加此服务引用时,它显示为字节[],正如Shiraz正确指出的,正如我刚刚了解到的,silverlight仅支持缓冲传输模式。您可以尝试实现一个逐个上传图像的解决方案。rwwilden-Silverlight也支持流模式,Shiraz的意思是System.Io。Silverlight在wcf服务中用作参数时不支持流,但当我尝试在Silverlight客户端中以编程方式配置BasicHttpBinding时,BasicHttpBinding上甚至不存在属性TransferMode。所以唯一可能的方法是通过套接字,我想?在Silverlight客户端上,我们无法配置传输模式,它只能在WCF服务上配置。Silverlight有很多限制,谢谢您的回复!我已经将该属性设置为流。当我在Windows项目中添加此服务引用时,它显示IO.Stream,但当我在silverlight项目中添加此服务引用时,它显示为字节[],正如Shiraz正确指出的,正如我刚刚了解到的,silverlight仅支持缓冲传输模式。您可以尝试实现一个逐个上传图像的解决方案。rwwilden-Silverlight也支持流模式,Shiraz的意思是System.Io。Silverlight在wcf服务中用作参数时不支持流,但当我尝试在Silverlight客户端中以编程方式配置BasicHttpBinding时,BasicHttpBinding上甚至不存在属性TransferMode。所以唯一可能的方法是通过套接字,我想?在Silverlight客户端上,我们无法配置传输模式,它只能在WCF服务上配置。Silverlight中有很多限制,为什么要这样做?你想得到上传进度条吗?你为什么想要这个?您正在尝试获取上载进度条吗?