先上两个配置文件,我已分别设置MaxReceivedMessageSize 为最大值,标红部分。
[code=客户端]
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1454/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference3.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
[/code]
[code=服务器端]
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="FileUDB" connectionString="D:\dd\"/>
</connectionStrings>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "D:\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--获取对象图中要序列化或反序列化的最大项数-->
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="NewBinding0"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
[/code]
配置文件如上,报错信息是
已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。
我传的参数是CompositeType,也就是IService里本来就有的那个,在其中添加了一个ObservableCollection
我在客户端调用的代码如下
ServiceReference3.Service1Client client = new ServiceReference3.Service1Client();
//(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
//(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
ServiceReference3.CompositeType type = new ServiceReference3.CompositeType() { DicFiledInfo = info, IsLast = true, UpStep = 1 };
client.CreateDatasourceAsync(type);
client.CreateDatasourceCompleted += new EventHandler<ServiceReference3.CreateDatasourceCompletedEventArgs>(client_CreateDatasourceCompleted);
client.CloseAsync();
注释部分放开的话仍然会报一样的错误。
我在CSDN上找到一个老帖
http://bbs.csdn.net/topics/320086503他是自己new了一个bind,没有调到配置文件。我的情况似乎不一样,求解答。
我用的是Silverlight4.0和VS10