WCF 传输大量数据 出错!!

cfsjjjj 2010-08-05 10:09:57
wcf 默认传输文件只能小于56kb,我怎么该配置文件都不行。麻烦大家帮我改改 谢谢!!
原始文件
web。config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>


ServiceReferences.ClientConfig:

<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:2649/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>

谢谢!!!
...全文
97 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cfsjjj 2010-08-05
  • 打赏
  • 举报
回复
<behavior name="xxxxxxxx.WCF.WCFServicesBehavior">
怎么加上名字 就报错了
手抓宝 2010-08-05
  • 打赏
  • 举报
回复
Web.Config

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="xxxxxxxx.WCF.WCFServicesBehavior">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


试一下。


另外可以在WCF中引用程序集 SharpZipLib.dll进行数据的压缩和解压:


WCF中压缩:

#region 压缩数据
/// <summary>
/// 序列化并压缩
/// </summary>
/// <param name="CompressData"></param>
/// <returns></returns>
public byte[] SerializerAndCompress(object CompressData)
{
byte[] b = Serialize(CompressData);
byte[] b2 = Compress(b);
return b2;
}

public byte[] Serialize(Object inst)
{
Type t = inst.GetType();
var dcs = new DataContractSerializer(t);
var ms = new MemoryStream();
dcs.WriteObject(ms, inst);
return ms.ToArray();
}

public byte[] Compress(byte[] bytData)
{
try
{
var ms = new MemoryStream();
var defl = new Deflater(9, false);
Stream s = new DeflaterOutputStream(ms, defl);
s.Write(bytData, 0, bytData.Length);
s.Close();
byte[] compressedData = ms.ToArray();
return compressedData;
}
catch
{
throw;
}
}
#endregion



SL中解压:

Wrapper wr = new Wrapper();
List<xxx> listXXX= (List<xxx>)wr.DecompressAndDeserialize(listXXX.GetType(), e.Result);
手抓宝 2010-08-05
  • 打赏
  • 举报
回复

<behaviors>
<serviceBehaviors>
<behavior name="xxxxxx.WCF.WCFServicesBehavior">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<!--这里的名字和behavior是对应的-->
<service behaviorConfiguration="xxxxx.WCF.WCFServicesBehavior" name="xxxx.WCF.WCFServices">
<endpoint address="" binding="basicHttpBinding" contract="xxxx.WCF.WCFServices"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧