如何更改maxBufferSize& WCF Wrapper服务中的maxReceivedMessageSize?

时间:2013-09-17 17:20:18

标签: c# asp.net .net wcf silverlight

从我的Silverlight 4项目中,我调用了一个WCF服务,该服务可以通过包装器服务访问。这只是一个WCF服务应用程序,其中包含对我的其他WCF的服务引用。我得到以下例外:

  

“传入邮件的最大邮件大小限额(65536)已经过   超标。要增加配额,请使用MaxReceivedMessageSize   适当的绑定元素上的属性。“。

调试时我看到:

  

ProtocolException未被用户代码处理 - 远程服务器   返回了意外的回复:(400)错误请求。

在Silverlight中,即使服务发送不同的错误代码,也可能会报告404响应代码。

我正在使用Silverlight 4& .NET 4.0。

我可以更改maxBufferSize& WCF测试客户端中的maxReceivedMessageSize为524288,以查看我的预期结果。

如何更改这些值以便实际使用它们而不是WCF默认设置?

Wrapper Service web.config:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IMyService" closeTimeout="00:02:00"
          openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="524288" maxBufferPoolSize="524288" maxReceivedMessageSize="524288"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="524288" maxStringContentLength="524288" maxArrayLength="524288"
            maxBytesPerRead="524288" maxNameTableCharCount="524288" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://internal:51505/SvcApp/MySvc_MyService.svc"
          binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IMyService"
          contract="WCFServiceRef.IMyService"
          name="BasicHttpBinding_IMyService" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Web项目web.config:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpsBinding_IMyWrapperService" maxBufferSize="524288"
       maxReceivedMessageSize="524288">
        <security mode="Transport" />
      </binding>
      <binding name="BasicHttpBinding_IMyWrapperService" closeTimeout="00:02:00"
       openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
       allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
       maxBufferSize="524288" maxBufferPoolSize="524288" maxReceivedMessageSize="524288"
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
       useDefaultWebProxy="true">
        <readerQuotas maxDepth="524288" maxStringContentLength="524288" maxArrayLength="524288"
         maxBytesPerRead="524288" maxNameTableCharCount="524288" />
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None"
           realm="" />
          <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://internal/mysvc/MyWrapperService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IMyWrapperService"
              contract="WrapperServiceServiceRef.IMyWrapperService"
              name="BasicHttpBinding_IMyWrapperService" />
  </client>
</system.serviceModel>

我已经看到了为serviceBehavior命名并添加maxItemsInObjectGraph的建议。

我尝试添加“LargeEndpointBehavior”,但这似乎没有做任何事情。

<client>
  <endpoint address="http://internal:51505/SvcApp/MySvc_MyService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IMyService"
      contract="WCFServiceRef.IMyService"
      name="BasicHttpBinding_IMyService"
      behaviorConfiguration="LargeEndpointBehavior" />
</client>

<behaviors>
  <serviceBehaviors>
    <behavior name="LargeEndpointBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我只需要修复我的服务包装器web.config吗?

我通过包装器调用的服务,我的Silverlight项目中的ServiceReferences.ClientConfig&amp;托管我的xap文件的Web应用程序的所有值都已超出。

有什么建议吗?

0 个答案:

没有答案