我已经搜索并尝试了之前发布的所有建议的解决方案,并且没有任何运气。我显然做错了什么,我无法弄明白,我希望有人能在这里帮助我。我的问题是:
我有一个WCF服务和一个WCF客户端。当我调用服务并尝试传递一个字节数组(将图像上传到服务)时,我得到一个非常模糊的Target Invokation异常错误。所以,我连接了跟踪,跟踪日志告诉我消息配额大小超过限制,但我已经修改了两端的配置(app.config和web.config)以包含一个非常大的限制。问题是,它告诉我超过了65536的限制,但正如你从我的配置中看到的那样,它的数量大于该数量,所以就好像我的客户端正在使用其他一些配置值,或者我只是没有配置它是正确的,它忽略了我拥有的东西。有人能帮我吗?
App.Config中:
Web.Config中:
你们可以提供的任何帮助将不胜感激。我已经坚持了两天这个问题。
谢谢大家。
这是实际的配置代码:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataSyncService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/DataSyncWCF/DataSyncService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataSyncService"
contract="IDataSyncService" name="WSHttpBinding_IDataSyncService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Web.Config中:
<services>
<service behaviorConfiguration="DataSyncWCF.Service1Behavior"
name="DataSyncWCF.DataSyncService">
<endpoint address="" binding="wsHttpBinding" bindingName="WSHttpBinding_IDataSyncService"
contract="DataSyncWCF.IDataSyncService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="DataSyncWCF.Service1Binding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" allowCookies="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DataSyncWCF.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
这是我调用WCF服务的代码:
VehicleImage vi = new VehicleImage();
System.IO.FileStream fs = new System.IO.FileStream(@"C:\images\1FAHP35N18W1589_01.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read);
int len = (int)fs.Length;
vi = new VehicleImage();
vi.Image = new Byte[len];
fs.Read(vi.Image, 0, len);
// Here's the call to the WCF Service. It never makes it to the Service because of the message size limit error.
ResponseContract rc = client.SyncImage(vi);
答案 0 :(得分:4)
WCF中的所有内容都受到严重限制(受限制),并且有理由。
我在配置中看到了很多2G号码,一般来说这不是一个好主意。你可能错过了一些,我无法如此快速地发现SerializationLimit(大概名字)。
有两种基本方法可以处理WCF中的大型消息:MTOM和流式传输。
答案 1 :(得分:1)
在你的web.config wsHttpBinding中,设置maxReceivedMessageSize
:
<binding name="www" maxReceivedMessageSize="2147483647">