WCF:服务器响应错误请求(400)

时间:2012-07-08 21:56:17

标签: arrays wcf exception app-config mtom

我的WCF客户端可以正常使用WCF服务器,除非在尝试传递自定义对象数组时调用服务器。当数组是100项时,它工作正常,但当项目数为300时,服务器抛出异常错误请求(400)。所以我假设解决方案的关键在于配置文件。

首先,这是客户端的app.config。 WCF客户端驻留在作为Outlook加载项的DLL中。我将此app.config复制到Outlook.exe.config到Outlook安装目录 - 这是Outlook加载加载项所需的内容:

<configuration>
  <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IJabberSvc" closeTimeout="00:01:00"           openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="Message">
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:9047/switchvox/alerter" binding="wsDualHttpBinding"
                bindingConfiguration="WSDualHttpBinding_IJabberSvc" contract="JabberService.IJabberSvc"
                name="WSDualHttpBinding_IJabberSvc">   
            </endpoint>
        </client>
    </system.serviceModel>
  <system.diagnostics>
    <trace autoflush="true" />
    <sharedListeners>
      <add name="sharedListener"
      type="System.Diagnostics.XmlWriterTraceListener"  initializeData="%AppData%\Mfg\ProjectName\Logs\SwitchvoxDialerTraceLog.svclog" />
    </sharedListeners>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sharedListener"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
        <listeners>
          <add name="sharedListener" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

  <userSettings>
    <SwitchvoxDialer.Properties.Settings>
      <setting name="InstallSubFolder" serializeAs="String">
        <value>Mfg\\ProjectName</value>
      </setting>
      <setting name="DialerTitle" serializeAs="String">
        <value>ProjectName</value>
      </setting>
    </SwitchvoxDialer.Properties.Settings>
  </userSettings>
</configuration>

服务器配置的相关部分如下所示:

  <system.serviceModel>
    <services>
      <service name="WcfServiceLib.JabberSvc" behaviorConfiguration="JabberSvc">
        <endpoint address="http://localhost:9047/switchvox/alerter"      binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IJabberSvc" contract="WcfServiceLib.IJabberSvc" name="WSDualHttpBinding_IJabberSvc">
          <identity>

        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9047/switchvox/alerter"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="JabberSvc">
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483646" />
          <serviceTimeouts transactionTimeout="00:10:00" />
          <!-- 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"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IJabberSvc" closeTimeout="00:01:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                 bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                 messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00"/>
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <!-- Enable message tracing by adding this section - Remove for production code -->
    <diagnostics>
      <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="true"
      maxMessagesToLog="100000" />
    </diagnostics>

  </system.serviceModel>

app.config在bin / Debug中生成ServerName.exe.config(以前我把它作为嵌入式资源,但它没有帮助......

正如您所看到的,我将缓冲区,消息等的所有数字增加到最大值,并确保时间值足够高......我确信问题在于某种方式无论是服务器还是客户端不知道这些增加的价值,但无法弄清楚为什么......

2 个答案:

答案 0 :(得分:1)

尝试使用MTOM进行邮件编码。有关详细信息,请参阅以下链接:

http://msdn.microsoft.com/en-us/library/ms733742.aspxhttp://msdn.microsoft.com/en-us/library/aa395209.aspx

如果这不起作用,请使用Fiddler获取有关错误的更多信息。 400差的请求可能意味着很多事情。

答案 1 :(得分:1)

WCF不会返回/显示有关其实际错误的信息(悲伤)。尝试配置WCF Tracing,看看它是否有帮助。