首页 > 解决方案 > WCF - 将大数据集返回给客户端

问题描述

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

“已超出传入邮件 (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

标签: wcfwcf-binding

解决方案


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

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

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


推荐阅读