2010-11-15 135 views
3

我无法找到此问题的答案。通过调整web.config文件中的一些最大大小设置,大多数类似的帖子精简似乎已被修复。但是,这些建议都没有解决我的问题。WCF错误 - 意外的响应:(400)错误的请求

为了给出更多背景,我将一个asmx Web服务移植到Windows Azure中承载的WCF Web服务。测试期间出现这个问题。如果我在一次调用中将少量事务传递给我的web服务,它往往工作得很好。虽然我的交易规模大约在50-60(交易)时出现这个错误。序列化到XML,文件大小约为300K,所以它没有任何疯狂的大。但它倾向于倾向于尺寸问题。

此外,接通WCF跟踪,我发现下面的例外发生的历史:

System.ServiceModel.ProtocolException:最大消息大小配额用于传入消息(65536)已经被超过。要增加配额,请在适当的绑定元素上使用MaxReceivedMessageSize属性。

在System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(字符串消息,HttpStatusCode的StatusCode,字符串状态说明)

在System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()

在System.ServiceModel.Channels .HttpInput.ReadBufferedMessage(流的inputStream)

在System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(例外&放大器;放大器; requestException)

在System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext背景下,操作回调)

从异常

所以,它看起来好像其中一个设置,如果关在我的web.config,但这里是什么看起来像:

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    <behavior name="MetadataEnabled"> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceMetadata httpGetEnabled="true"/> 
     <useRequestHeadersForMetadataAddress> 
     <defaultPorts> 
      <add scheme="http" port="8081"/> 
      <add scheme="https" port="444"/> 
     </defaultPorts> 
     </useRequestHeadersForMetadataAddress> 
     <dataContractSerializer maxItemsInObjectGraph="111024000"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled"> 
    <endpoint name="HttpEndpoint" 
       address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttp" 
       contract="Bandicoot.CORE.IRepricer" /> 
    <endpoint name="HttpMetadata" 
       address="contract" 
       binding="mexHttpBinding" 
       bindingConfiguration="mexBinding" 
       contract="Bandicoot.CORE.Stack" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/Core"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxBytesPerRead="111024000" 
        maxArrayLength="111024000" 
        maxStringContentLength="111024000"/> 
     <security mode="None"/> 
    </binding> 
    </wsHttpBinding> 
    <mexHttpBinding> 
    <binding name="mexBinding"/> 
    </mexHttpBinding> 
</bindings> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

没有人有任何其他建议,或者有在我的web.config,我只是没有看到的东西误配置的?

感谢您的任何建议!

编辑:这是我的客户的app.config设置

<bindings> 
<basicHttpBinding> 
    <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="14194304" maxBufferPoolSize="14194304" maxReceivedMessageSize="14194304" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="1000" maxStringContentLength="111024000" 
      maxArrayLength="111024000" maxBytesPerRead="1024000" maxNameTableCharCount="111024000" /> 
     <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
</basicHttpBinding> 

编辑:添加另外的客户信息:

 <client> 
     <endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE" 
      name="BasicHttpBinding_CORE" /> 
    </client> 

编辑:尝试改变服务绑定到basicHttpBinding的 - 配置更改:

 <basicHttpBinding> 
    <binding name="basicHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxArrayLength="111024000" maxBytesPerRead="111024000" maxStringContentLength="111024000"/> 
     <security mode="None" /> 
    </binding> 
    </basicHttpBinding> 

     <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled"> 
    <endpoint binding="basicHttpBinding" 
       bindingConfiguration="basicHttp" 
       contract="Bandicoot.CORE.IRepricer" /> 
    <endpoint address="mex" 
       binding="mexHttpBinding" 
       bindingConfiguration="mexBinding" 
       contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/Core"/> 
     </baseAddresses> 
    </host> 
    </service> 

和客户端的应用程序。配置以及供参考:

 <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="100000000" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE" 
      name="BasicHttpBinding_CORE" /> 
    </client> 
+0

和使用**这些设置是你的客户端终端实际上​​*? – 2010-11-15 19:46:03

+0

你的服务定义了'wsHttpBinding' - 你的客户有'basicHttpBinding'设置.....是那些即使匹配了?此外 - 你没有告诉我们的' ...'你的客户的配置的部分 - 这将是最有趣的! – 2010-11-15 20:44:43

+0

@marc_s - 此客户端配置的大部分只是由Visual Studio中的“添加服务引用”功能自动生成的。由于我们的客户都将消耗该Web服务,这将是可取的,如果他们没有需要破解了一个配置文件,我们的服务工作...这可能是在它自己的另外一个问题,所以现在我只是想获得它工作。我已经发布了我的配置文件的客户端部分。请让我知道,如果你看到任何看起来不正确的东西。谢谢! – Brosto 2010-11-15 21:04:32

回答

1

今天早上我终于明白了这一点。问题在于我的服务没有使用我认为是的配置设置。原因?配置中的服务名称必须是正在实施的服务的完全限定路径。

我发现这个link有用计算出来。

我觉得我的服务没有指向实际的端点有点奇怪,我想它只是使用一系列的默认值,如果你想有不同的东西,你可以在web.config中配置它们吗?我认为这解释了为什么当我在客户端中使用webservice而不是wsHttpBinding时,我得到了一个basicHttpBinding。

花了几天的时间弄清楚,但是很有教育意义。感谢您的建议!

2

您需要在客户端上要设置maxReceivedMessageSize(你在哪里从服务返回的消息是进入) - 在其app.configweb.config

<system.serviceModel> 
<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxBytesPerRead="111024000" 
        maxArrayLength="111024000" 
        maxStringContentLength="111024000"/> 
     <security mode="None"/> 
    </binding> 
    </wsHttpBinding> 
    <mexHttpBinding> 
    <binding name="mexBinding"/> 
    </mexHttpBinding> 
</bindings> 
<client name="whatever"> 
    <endpoint name="HttpEndpoint" 
     address="" 
     binding="wsHttpBinding" 
     bindingConfiguration="wsHttp" 
     contract="Bandicoot.CORE.IRepricer" /> 
</client> 
</system.serviceModel> 

maxReceivedMessageSize的默认值是64K,除非您更改它。

+0

对不起,我没有包含我的客户端配置,我也有这个设置。我用我的app.config设置更新了原始问题。 – Brosto 2010-11-15 19:18:26

+0

正如@marc_s指出的那样,客户端似乎没有使用这些设置。错误消息清楚地表明,电流限制是64K。 – TMN 2010-11-15 20:36:15

+0

我使用客户端配置更新了原始帖子。会喜欢一些额外的建议。 – Brosto 2010-11-16 15:32:28

1

我有同样的错误,原因显露是配置错误了。

但在这种情况下,我是,像marc_s已经发布,在服务器端maxReceivedMessageSize设置。该服务器仍在使用其默认配置,该配置低至64 kb。

可以明显看出这是因为现在的声音,那么久花了我找出的错误并不在我的(客户端)的一面。

我希望这可以帮助别人。

0

嗨问题海报“Brosto”!

这补充你的11月17日在'10 15:29答案。

我们有一个“乐趣”,或者我应该说今天的“教育”生产部署测试问题,一天中大部分时间都需要解决,而且它实际上是由一次按键引起的。在Web Farm完全部署后,我们发现问题消失后,我们只确认问题的根源。

这是原因。当我们测试我们的生产部署,并针对“单台服务器”做到通过改变我们的hosts文件,我们绕过负载均衡器,并调用单个服务器最终会在默认http端口!当我们测试对“负载均衡”,调用从负载平​​衡器单个服务器,最终会在负载平衡器定义的端口!

由于服务端点地址必须是“完全限定”,以使服务能够找到服务的自定义绑定。在单一服务器上的配置文件必须改变,以反映“单服务器”与“负载平衡服务器”端点连接之间的差异,具体如下:

单服务器连接:

endpoint address="http://www.myserver.com:80/Services/MyService.svc" 

负载平衡服务器连接:

endpoint address="http://www.myserver.com:81/Services/MyService.svc" 

我的老板早期正确诊断的核心问题,他说,服务器充当像自定义绑定被忽略并且正在使用默认值。 显示出他的评论以上,其中你提到的“完全合格”的服务端点地址的要求后,他意识到,主机文件重定向是造成的,而不是我们的浏览器请求去了默认的端口80的单服务器,负载平衡端口81,这实际上改变了完全合格的服务端点地址,导致服务器忽略这些自定义绑定并恢复到默认设置。 请注意,它不会调用服务,它只会绑定自定义绑定失败!

希望有人会记住这一点发布,下一次我们生产测试服务与自定义绑定:)