use*_*195 2 c# wcf serialization
我有一个WCF服务,我希望将一些文件从服务器传输到客户端.
当我硬编码文件的文件名以流入代码时,我已经有了这个工作.
我正在尝试更改代码,以便getStream方法返回一个Dictionary,这样我就可以返回文件名集合和与文件名关联的流,然后在客户端处理每个流.
在尝试调用getStream方法时,我在客户端获得以下异常:接收到http:// localhost:8082 /的HTTP响应时发生错误.这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭).请参阅服务器日志以获取更多详
在网上研究这个之后,看起来这是一个错误的异常所以我打开了跟踪,这是来自跟踪日志的异常消息:
尝试序列化参数http://tempuri.org/:GetStreamResult时出错.InnerException消息是'Type'System.IO.FileStream',数据协定名称为'FileStream:http://schemas.datacontract.org/2004/07/System.IO'不是预期的.考虑使用DataContractResolver或将任何静态未知的类型添加到已知类型列表中 - 例如,通过使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型列表中.有关更多详细信息,请参阅InnerException.
这是服务器端代码:
public Dictionary<String, Stream> GetStream()
{
Dictionary<String, Stream> retDic = new Dictionary<string, Stream>();
string[] fileEntries = Directory.GetFiles(@"C:\Users\Ash\Desktop\FrontendPluginsServer");
foreach (string fileName in fileEntries)
{
//do something with fileName
retDic.Add(fileName, File.OpenRead(fileName));
}
//return File.OpenRead(@"C:\Users\Ash\Desktop\FrontendPluginsServer\OptekImporterFrontend.dll");
return retDic;
}
Run Code Online (Sandbox Code Playgroud)
这是客户端代码:
ModuleDownloader.ModuleDownloaderClient moo = new ModuleDownloader.ModuleDownloaderClient();
Dictionary<String, Stream> dic = moo.GetStream();
foreach (String key in dic.Keys)
{
using (Stream file = File.OpenWrite(@"C:\Users\Ash\Desktop\FrontEndPluginsClient\" + key)) { CopyStream(dic[key], file); }
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请告诉我.
亲切的问候
灰
| 归档时间: |
|
| 查看次数: |
5075 次 |
| 最近记录: |