【问题标题】:WCF - Return large data set to ClientWCF - 将大数据集返回给客户端
【发布时间】:2020-01-09 17:18:47
【问题描述】:

目标是将表的内容作为数据集发送给客户端。我从客户端应用程序收到错误:

“已超出传入邮件的最大邮件大小配额 (65536)。”

虽然在同一个 WCF 应用程序中检索来自客户端的大量数据没有错误。 请查看配置文件。

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>

<bindings>
  <wsHttpBinding>
    <binding name="TeansferBinding" 
             messageEncoding="Mtom" 
             maxBufferPoolSize="2147483647" 
             maxReceivedMessageSize="2147483647" 
             receiveTimeout="00:10:00">
      <readerQuotas maxDepth="2147483647" 
                    maxStringContentLength="2147483647" 
                    maxArrayLength="2147483647"/>
      <!-- 
        For forced HTTPS
        change the security mode from None to Transport and add Transport key with clientCredentialType="None"
        <security mode="Transport">
          <transport clientCredentialType="None"/>
        </security
      -->
      <security mode="None" />
    </binding>
    <binding name="ProjectBinding"
             messageEncoding="Text"
             maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647"
             receiveTimeout="00:10:00">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"/>
      <!-- 
        For forced HTTPS
        change the security mode from None to Transport and add Transport key with clientCredentialType="None"
        <security mode="Transport">
          <transport clientCredentialType="None"/>
        </security
      -->
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>

    <behavior name="TransferBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. -->
      <!-- Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500"/>
    </behavior>

  </serviceBehaviors>
</behaviors>

<services>

  <service behaviorConfiguration="TransferBehavior" name="TransferServer.Restore" >
    <endpoint address="" 
              binding="wsHttpBinding" 
              bindingConfiguration="TeansferBinding" 
              contract="TransferServer.IRestore"/>
    <!-- remove mex endpoint of production server -->
    <endpoint address="mex" 
              binding="mexHttpBinding" 
              name="Mex" 
              contract="IMetadataExchange"/>
    <host>
      <timeouts closeTimeout="00:10:00" openTimeout="00:10:00"/>
    </host>
  </service>

  <service behaviorConfiguration="TransferBehavior" name="TransferServer.ProjectProvider">
    <endpoint address="" 
              binding="wsHttpBinding" 
              bindingConfiguration="ProjectBinding" 
              contract="TransferServer.IProjectProvider"/>
    <!-- remove mex endpoint of production server -->
    <endpoint address="mex" 
              binding="mexHttpBinding" 
              name="Mex" 
              contract="IMetadataExchange"/>
    <host>
      <timeouts closeTimeout="00:10:00" openTimeout="00:10:00"/>
    </host>
  </service>

</services>

我已经搜索过解决方案,但只是回到了配置文件的调整。 WCF 应用程序没有报告任何错误,客户端正在报告错误。

我尝试使用 wsHttpBinding 和 basicHttpBinding 没有成功。我已经尝试过 MTOM 和短信编码。


@亚伯拉罕·钱

客户端应用配置文件

这是客户端的 App.Config 文件。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IRestore" messageEncoding="Mtom">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                    </security>
                </binding>
                <binding name="WSHttpBinding_IProjectProvider">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myServer.com/Restore.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRestore"
                contract="RestoreProvider.IRestore" name="WSHttpBinding_IRestore" />
            <endpoint address="https://myServer.com/ProjectProvider.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProjectProvider"
                contract="ProjectProvider.IProjectProvider" name="WSHttpBinding_IProjectProvider" />
        </client>
    </system.serviceModel>
</configuration>

至于 ProjectProvider 服务的绑定信息,唯一的区别是“maxBufferSize”,它在插入时会产生错误。

客户端中的使用代码

Public sub GetZips()
    'Get the information from Ops
    Using oProjectProvider As New ProjectProvider.ProjectProviderClient
        MyDataSet = oProjectProvider.GetZipCodeData
        oProjectProvider.Close()
    End Using
    Application.DoEvents()
End sub

【问题讨论】:

  • 你在app.config中设置了客户端的maxReceivedMessageSize吗?

标签: wcf wcf-binding


【解决方案1】:

我想知道客户端配置。你如何创建对服务的调用?我们最好在客户端和服务器端都应用配置。此外,我怀疑客户端服务端点地址有问题。请发布完整的客户端配置。
另外,请参考下面的配置。

<binding maxBufferPoolSize="2147483647" 
         maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647" 
                  maxStringContentLength="2147483647" 
                  maxArrayLength="2147483647" 
                  maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647" />
</binding>

如果问题仍然存在,请随时告诉我。

【讨论】:

  • 查看更新信息。我希望我能理解您的要求并提出修改建议。感谢您的关注!
  • 我从您的配置文件中删除了“maxBufferSize”并将其放入应用程序的 App.Config 文件中,它可以工作!是的,感谢您的帮助。
猜你喜欢
  • 2011-05-05
  • 2017-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-22
  • 2011-04-25
  • 1970-01-01
相关资源
最近更新 更多