看起来这个问题已被问过千次,但每个人的配置问题都不同。我有WCF服务器,它提供图像并接收上传图像请求。上传图片时,当大小超过65k时,我收到错误400.
我在WCF上打开了跟踪,我收到了确切的错误
传入邮件的最大邮件大小限额(65536) 超标。要增加配额,请使用MaxReceivedMessageSize 适当的绑定元素上的属性。
我知道我需要增加这些参数,但我只能找到它应该在我的web.config文件中的位置。这是我在web.config中的内容:
<system.serviceModel>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<services>
<service behaviorConfiguration="ReportTransferServiceBehavior" name="ReportTransferService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="IReportTransferService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="ReportTransferServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<domainServices>
<endpoints>
<add name="json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
maxReceivedMessageSize="2000000" />
</endpoints>
</domainServices>
<bindings>
<basicHttpBinding>
<binding name="ReportTransferService" maxReceivedMessageSize="2000000" maxBufferSize="2000000" transferMode="Streamed">
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
<security mode="None"></security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
我发送图片的网址(HTTP POST)是hostname/ReportTransferService.svc/UploadImage
。看起来它正在使用某种默认绑定,而不是basicHttpBinding
配置为更大的大小。
任何人都可以告诉我我的web.config有什么问题吗?
更新:已解决
我必须在服务配置和serviceBehavior配置中为ReportTransferService指定完全限定名称,并添加具有类似限制和指向服务的全新webHttpBinding部分以使用此绑定。
感谢您的帮助。
答案 0 :(得分:1)
您的服务部分应具有完全限定名称,如下所示:
<services>
<service behaviorConfiguration="ReportTransferServiceBehavior" name="namespace.ReportTransferService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="namespace.IReportTransferService"></endpoint>
</service>
</services>