【问题标题】:Calling a Service reference results in a "The remote server returned an error: (400) Bad Request" error调用服务引用会导致“远程服务器返回错误:(400) 错误请求”错误
【发布时间】:2011-07-24 11:53:13
【问题描述】:

edit3:我从服务器添加了 webconfig

edit2:我运行了日志,这是出现的错误消息:

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

由于它仅针对 2000 条记录的测试而不是针对 200 条记录的测试执行此操作,因此我决定更改应用程序设置,假设它超过了 65535 的标准限制。不幸的是,这没有帮助,我四处搜索发现这个问题还有两种其他类型的起源,一种是服务本身的设置,另一种是端点中的设置。

提供服务的开发人员说他这边没问题,问题只是我这边的一个设置,他曾经自己做过但不记得了。

我已经添加了端点的应用程序配置数据,人们说如果端点不匹配,将使用默认设置创建一个默认端点,因此使用 65K 限制。如果这是问题,我该如何解决?

如果您需要任何额外的代码或信息,请告诉我。

编辑:我按照建议将更改添加到应用配置中

<behaviors>
  <endpointBehaviors>
    <behavior name="MetadataBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>


    <binding name="BasicHttpBinding_IMailSortService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                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>


    <endpoint behaviorConfiguration="MetadataBehavior" address="http://remote-access/MailSort/MailSortService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMailSortService"
        contract="MailSortServiceReference.IMailSortService" name="BasicHttpBinding_IMailSortService" />

服务器上的网络配置

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="FilePath" value="\\162.27.51.43\DOWNLOAD\RPA\Mailsort\Auto" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>

   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "c:\logs\Traces.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 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"/> 
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

【问题讨论】:

  • 看看maxItemsInObjectGraph属性,也许这会对你有所帮助
  • 我添加了该行为,但不幸的是它仍然带有错误的请求。不过,我会进一步研究行为选项,看看是否还有其他可能性。
  • 您确实在服务的 配置部分中配置了 basicHttpBinding 对吗? maxItemsInObjectGraph 和 MaxRecieveivedMessageSize 等一样吗?
  • 你能发布详细的异常堆栈跟踪吗?在客户端包含异常错误时,您还可以发布您正在调用的方法的签名吗?

标签: c# wcf c#-4.0


【解决方案1】:

cmets 变得太大,进入答案:

您是否将端点指向该行为?

<endpoint address="http:blah/MyService.svc" behaviorConfiguration="MyServiceBehavior". 

当前配置适用于 200 但不适用于 2000?如果是这样,您是否可以尝试将您的服务绑定修改为如下所示的最大值,看看是否有帮助(您也会在服务端反映相同的属性)?

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

【讨论】:

  • 我已将配置添加到端点,并且之前尝试过提高读取配额但无济于事。我现在又试了一次,但它仍然给我错误的请求错误。
  • 我在运行这些更改时添加了我在日志中发现的错误。似乎没有获取我的 nd 点信息。
  • 您是否也在服务器端的服务配置中升级它们?
  • 我将 web.config 添加到原始问题中,与其他问题不同,其中似乎没有绑定,但这是因为根据服务创建者的说法,它是 c#4.0。 (stackoverflow.com/questions/784606/…)
  • 抱歉,安迪,我遇到了和你一样的错误,基本上是从我的服务配置中获取绑定并将它们粘贴到我的客户端中,然后错误就消失了……希望你也能这样。跨度>
【解决方案2】:

我没有看到为这篇文章启用了 cmets。

我不评论,而是给出答案。

根据下面的帖子,请确保您为服务合同使用完全限定的命名空间。

http://forums.silverlight.net/forums/p/191589/442378.aspx

<endpoint behaviorConfiguration="MetadataBehavior" address="http://remote-access/MailSort/MailSortService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMailSortService"
        contract="FullyQualifiedNamespace.IMailSortService" name="BasicHttpBinding_IMailSortService" />

【讨论】:

    【解决方案3】:

    解决方案是以下应用配置设置。

    通过 WCF 发送大型消息时,需要将以下代码添加到服务器上的 web.config 和本地应用程序上的 app.config 中。然后,这将使服务器和本地配置使用用户定义的消息大小。

    包含在部分内部。

    <protocolMapping>
    <remove scheme="http" />
    <add scheme="http" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMailSortService" />
    </protocolMapping>
    

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多