C# 尝试序列化参数时出错
我有一个WCF服务,我想把一些文件从服务器传输到客户端 当我硬编码文件名以流式传输到代码中时,我已经实现了这一点 我正在尝试更改代码,以便getStream方法返回一个字典,这样我就可以返回一组文件名和与文件名关联的流,然后在客户端处理每个流 尝试调用getStream方法时,客户端出现以下异常: 接收对的HTTP响应时出错。这可能是由于服务端点绑定未使用HTTP协议造成的。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志 在网上研究后,这似乎是一个错误的异常,所以我打开了跟踪,这是来自跟踪日志的exceptionn消息: 尝试序列化参数时出错。InnerException消息为'Type'System.IO.FileStream',数据协定名称为'FileStream:http://schemas.datacontract.org/2004/07/System.IO”他说。考虑使用DATACONTRORTCORDEVER或将未知类型的任何类型添加到已知类型的列表中——例如,通过使用NoNyType属性,或者将它们添加到传递给DATACONTROTTRORALIZER的已知类型列表中。有关更多详细信息,请参阅InnerException 以下是服务器端代码:C# 尝试序列化参数时出错,c#,wcf,serialization,C#,Wcf,Serialization,我有一个WCF服务,我想把一些文件从服务器传输到客户端 当我硬编码文件名以流式传输到代码中时,我已经实现了这一点 我正在尝试更改代码,以便getStream方法返回一个字典,这样我就可以返回一组文件名和与文件名关联的流,然后在客户端处理每个流 尝试调用getStream方法时,客户端出现以下异常: 接收对的HTTP响应时出错。这可能是由于服务端点绑定未使用HTTP协议造成的。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志 在网上研究后,这似乎是
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;
}
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); }
}
公共字典GetStream()
{
Dictionary retDic=新字典();
string[]fileEntries=Directory.GetFiles(@“C:\Users\Ash\Desktop\FrontendPluginsServer”);
foreach(文件项中的字符串文件名)
{
//对文件名做些什么
Add(文件名,File.OpenRead(文件名));
}
//返回文件.OpenRead(@“C:\Users\Ash\Desktop\frontendpluginserver\optekimporterfronted.dll”);
返回retDic;
}
以下是客户端代码:
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;
}
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); }
}
ModuleDownloader.ModuleDownloaderClient moo=new ModuleDownloader.ModuleDownloaderClient();
Dictionary dic=moo.GetStream();
foreach(dic.Keys中的字符串键)
{
使用(Stream file=file.OpenWrite(@“C:\Users\Ash\Desktop\FrontEndPluginsClient\”+key)){CopyStream(dic[key],file);}
}
如果您需要更多信息,请告诉我
问候
灰烬你不可能做到这一点
不可序列化。它尝试序列化它的原因是它不遵循WCF流媒体约定FileStream
- WCF对流媒体的限制定义了,如果要使用WCF流媒体,则必须在方法签名中有一个
流
阅读更多信息。谢谢您的帮助。我想我可以通过调用服务器返回当前文件名的列表,然后调用getStream返回该文件的单个流来完成我想要的任务?或者你能想出更好的办法吗?我想不出更好的办法了。我会像你说的那样做。有完整源代码的最终解决方案吗?