1

我的 WCF 客户端可以在 WCF 服务器上正常工作,除非在尝试传递自定义对象数组时调用服务器。当数组为 100 项时,它可以正常工作,但当项数为 3​​00 时,服务器会抛出异常 Bad Request (400)。所以我认为解决方案的关键在于配置文件。

首先是客户端的 app.config。WCF 客户端驻留在一个 DLL 中,即 Outlook 加载项。我将此 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 (以前我将它作为嵌入式资源,但它也没有帮助......

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

4

2 回答 2

1

WCF 不会返回/显示大量关于其方面实际错误的信息(可悲)。尝试配置WCF 跟踪,看看是否有帮助。

于 2012-07-09T02:47:21.237 回答
1

尝试使用 MTOM 进行消息编码。有关更多信息,请参阅以下链接:

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

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

于 2012-07-08T23:11:42.400 回答