C# 调用包含大量数据的web服务时出错

C# 调用包含大量数据的web服务时出错,c#,xml,wcf,C#,Xml,Wcf,我有一个本地托管的WCF服务。我的web.config如下所示: <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_INavigationService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTim

我有一个本地托管的WCF服务。我的web.config如下所示:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_INavigationService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>      
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />
</client>   
</system.serviceModel>
有人能告诉我如何增加文本配额吗?如您所见,我已将其设置为最大整数大小

编辑

根据Tim的建议,下面是我的新Web.Config文件:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>      
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />
</client>
<services>
  <service name="Navigation.INavigationService">

    <endpoint address="" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_INavigationService"
              contract="NavigationService.INavigationService"  />

  </service>
</services>


根据错误消息和您对问题的描述,您需要确保您的服务具有相同的设置,引用
端点
元素的
bindingConfig
attirbute中定义的相同绑定:

<system.serviceModel>
  <services>
    <service name="Navigation.INavigationService">
      <endpoint address="" 
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_INavigationService"
                contract="NavigationService.INavigationService" />
    </service>
  </services>
</system.serviceModel>
注意:未设置
名称
属性

在这种情况下,您可能需要使用选项1,或者创建一个没有名称的类似绑定定义,因为我不能100%确定客户机是否使用默认绑定;他们肯定是为了服务

有关默认绑定和端点的详细信息,请参阅

基于编辑的附加答案

试试这个:

<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
            binding="basicHttpBinding" 
            contract="NavigationService.INavigationService" 
            name="BasicHttpBinding_INavigationService" />
</client>


删除
部分,因为WCF 4.0的默认端点机制将为您处理该部分,并从客户端端点删除
bindingConfiguration
属性

根据错误消息和您对问题的描述,您需要确保您的服务具有相同的设置,引用
端点
元素的
bindingConfig
attirbute中定义的相同绑定:

<system.serviceModel>
  <services>
    <service name="Navigation.INavigationService">
      <endpoint address="" 
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_INavigationService"
                contract="NavigationService.INavigationService" />
    </service>
  </services>
</system.serviceModel>
注意:未设置
名称
属性

在这种情况下,您可能需要使用选项1,或者创建一个没有名称的类似绑定定义,因为我不能100%确定客户机是否使用默认绑定;他们肯定是为了服务

有关默认绑定和端点的详细信息,请参阅

基于编辑的附加答案

试试这个:

<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
            binding="basicHttpBinding" 
            contract="NavigationService.INavigationService" 
            name="BasicHttpBinding_INavigationService" />
</client>


删除
部分,因为WCF 4.0的默认端点机制将为您处理该部分,并从客户端端点删除
bindingConfiguration
属性

发布你的服务配置文件-看起来你需要增加那里的值,而不是在你的客户端上。你正在显示客户端的配置,你的服务器端是否也有相同的maxBuffer、contentLength、messageSize等配置?伙计们,我的服务和我的客户端在同一个IIS应用程序下运行,所以web.config对两者都是一样的。web.config的
部分是什么样子的?@Tim--我想我没有服务部分。我确实有一个System.ServiceModel部分,虽然发布了你的服务配置文件-看起来你需要增加那里的值,而不是在你的客户端上。你正在为客户端显示配置,你的服务器端是否也有相同的maxBuffer、contentLength、messageSize等配置?伙计们,我的服务和我的客户端在同一个IIS应用程序下运行,所以web.config对两者都是一样的。web.config的
部分是什么样子的?@Tim--我想我没有服务部分。我确实有一个System.ServiceModel部分,尽管我删除了名称标签并添加了标签。我是否需要在某个地方指定最大大小?只要绑定(没有名称属性)定义了较大的大小,您就可以了。@icemanind-您可以发布新的Web.config吗?我会看一看并做出回应。尝试删除客户端和服务的
bindingConfiguration
属性-这可能会把事情搞砸(老实说,我很惊讶服务甚至在运行时引用了一个不存在的绑定配置)。还要确保服务部分中的服务名称与.svc文件中指定的名称匹配。在.NET3.5中会发生什么?它也有默认的端点机制吗?我删除了name标签并添加了标签。我是否需要在某个地方指定最大大小?只要绑定(没有名称属性)定义了较大的大小,您就可以了。@icemanind-您可以发布新的Web.config吗?我会看一看并做出回应。尝试删除客户端和服务的
bindingConfiguration
属性-这可能会把事情搞砸(老实说,我很惊讶服务甚至在运行时引用了一个不存在的绑定配置)。还要确保服务部分中的服务名称与.svc文件中指定的名称匹配。在.NET3.5中会发生什么?它也有默认的端点机制吗?