'System.ServiceModel.Diagnostics.TraceUtility'的类型初始值设定项引发了异常

时间:2013-07-23 06:46:32

标签: api c#-4.0 timeout console-application app-config

我使用C#开发了一个控制台应用程序,以访问另一个API并提取相关数据。当我用少量数据输入检查时,它工作正常。虽然我正在使用大量数据进行负载测试,但它会引发异常。

例外是:

  

'System.ServiceModel.Diagnostics.TraceUtility'的类型初始值设定项引发了异常。

我的app.config:

<?xml version="1.0"?>
<configuration>
    <commonBehaviors>
        <serviceBehaviors>
            <serviceTimeouts transactionTimeout="01:55:00"/>
        </serviceBehaviors>
    </commonBehaviors>

    <bindings>
        <customBinding>
            <binding name="EloquaService"
                     closeTimeout="00:55:00"
                     openTimeout="00:55:00"
                     receiveTimeout="00:55:00"
                     sendTimeout="01:55:00">
                <security defaultAlgorithmSuite="Default"
                          authenticationMode="UserNameOverTransport"
                          requireDerivedKeys="true"
                          securityHeaderLayout="Strict"
                          includeTimestamp="true"
                          keyEntropyMode="CombinedEntropy"
                          messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">

                    <localClientSettings cacheCookies="true"
                                         detectReplays="false"
                                         replayCacheSize="900000"
                                         maxClockSkew="00:05:00"
                                         maxCookieCachingTime="Infinite"
                                         replayWindow="00:05:00"
                                         sessionKeyRenewalInterval="10:00:00"
                                         sessionKeyRolloverInterval="00:05:00"
                                         reconnectTransportOnFailure="true"
                                         timestampValidityDuration="00:05:00"
                                         cookieRenewalThresholdPercentage="60"/>
                    <localServiceSettings detectReplays="false"
                                          issuedCookieLifetime="10:00:00"
                                          maxStatefulNegotiations="128"
                                          replayCacheSize="900000"
                                          maxClockSkew="00:05:00"
                                          negotiationTimeout="00:01:00"
                                          replayWindow="00:05:00"
                                          inactivityTimeout="00:02:00"
                                          sessionKeyRenewalInterval="15:00:00"
                                          sessionKeyRolloverInterval="00:05:00"
                                          reconnectTransportOnFailure="true"
                                          maxPendingSessions="128"
                                          maxCachedCookies="1000"
                                          timestampValidityDuration="00:05:00"/>
                    <secureConversationBootstrap/>
                </security>
                <textMessageEncoding maxReadPoolSize="64"
                                     maxWritePoolSize="16"
                                     messageVersion="Soap11"
                                     writeEncoding="utf-8">
                    <readerQuotas maxDepth="32"
                                  maxStringContentLength="8192"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="4096"
                                  maxNameTableCharCount="16384"/>
                </textMessageEncoding>
                <httpsTransport manualAddressing="false"
                                maxBufferPoolSize="524288"
                                maxReceivedMessageSize="65536"
                                allowCookies="false"
                                authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false"
                                decompressionEnabled="true"
                                hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true"
                                maxBufferSize="65536"
                                proxyAuthenticationScheme="Anonymous"
                                realm=""
                                transferMode="Buffered"
                                unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true"
                                requireClientCertificate="false"/>
            </binding>
            <binding name="EmailServiceEndpoint"
                     closeTimeout="00:55:00"
                     openTimeout="00:55:00"
                     receiveTimeout="00:55:00"
                     sendTimeout="01:55:00">
                <security defaultAlgorithmSuite="Default"
                          authenticationMode="UserNameOverTransport"
                          requireDerivedKeys="true"
                          securityHeaderLayout="Strict"
                          includeTimestamp="true"
                          keyEntropyMode="CombinedEntropy"
                          messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
                    <localClientSettings cacheCookies="true"
                                         detectReplays="false"
                                         replayCacheSize="900000"
                                         maxClockSkew="00:05:00"
                                         maxCookieCachingTime="Infinite"
                                         replayWindow="00:05:00"
                                         sessionKeyRenewalInterval="10:00:00"
                                         sessionKeyRolloverInterval="00:05:00"
                                         reconnectTransportOnFailure="true"
                                         timestampValidityDuration="00:05:00"
                                         cookieRenewalThresholdPercentage="60"/>
                    <localServiceSettings detectReplays="false"
                                          issuedCookieLifetime="10:00:00"
                                          maxStatefulNegotiations="128"
                                          replayCacheSize="900000"
                                          maxClockSkew="00:05:00"
                                          negotiationTimeout="00:01:00"
                                          replayWindow="00:05:00"
                                          inactivityTimeout="00:02:00"
                                          sessionKeyRenewalInterval="15:00:00"
                                          sessionKeyRolloverInterval="00:05:00"
                                          reconnectTransportOnFailure="true"
                                          maxPendingSessions="128"
                                          maxCachedCookies="1000"
                                          timestampValidityDuration="00:05:00"/>
                    <secureConversationBootstrap/>
                </security>
                <textMessageEncoding maxReadPoolSize="64"
                                     maxWritePoolSize="16"
                                     messageVersion="Soap11"
                                     writeEncoding="utf-8">
                    <readerQuotas maxDepth="32"
                                  maxStringContentLength="8192"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="4096"
                                  maxNameTableCharCount="16384"/>
                </textMessageEncoding>
                <httpsTransport manualAddressing="false"
                                maxBufferPoolSize="524288"
                                maxReceivedMessageSize="65536"
                                allowCookies="false"
                                authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false"
                                decompressionEnabled="true"
                                hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true"
                                maxBufferSize="65536"
                                proxyAuthenticationScheme="Anonymous"
                                realm=""
                                transferMode="Buffered"
                                unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true"
                                requireClientCertificate="false"/>
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="https://secure.eloqua.com/API/1.2/service.svc"
                  binding="customBinding"
                  bindingConfiguration="EloquaService"
                  contract="EloquaService.EloquaService"
                  name="EloquaService"/>
        <endpoint address="https://secure.eloqua.com/API/1.2/ExternalActionService.svc"
                  binding="customBinding"
                  bindingConfiguration="EmailServiceEndpoint"
                  contract="EloquaProgramService.ExternalActionService"
                  name="EmailServiceEndpoint"/>
    </client>

    </system.serviceModel>

    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

这个问题已经克服了。可能我有两个app.config个文件。一个来自服务参考,另一个来自我的应用程序。两者都有相同的代码。我刚从appl.config中删除了以下代码,该代码放在我的应用程序中。现在它没有抛出上述异常。

<commonBehaviors>
    <serviceBehaviors>
        <serviceTimeouts transactionTimeout="01:55:00"/>
    </serviceBehaviors>
</commonBehaviors>

答案 1 :(得分:0)

刚才这件事发生在我身上。我想分享,即使它非常愚蠢。

这就是我做的事情

我在控制台应用程序中添加了对WCF服务的引用。

我在配置中添加了一个键值对值,而不是在配置中的appSettings部分。在我急于测试服务时,我运行了我的控制台应用程序并得到了完全相同的错误。

在进入错误详细信息时,我认为这是因为我的配置中的配置条目无效。

我在appSettings部分添加了键值对后,就可以了。我知道这很傻,但它仍然发生在我身上。 :)。

答案 2 :(得分:0)

我有类似的例外和问题

1)有两个配置文件并且具有类似的设置(服务层中的Web层/ web.config中的app.config - 我们正在调用外部服务)

2)web.config(log4net配置部分)

中的无效部分

Visual Studio没有显示没有#2的任何错误,因为它看起来对VS的有效部分,但在运行时它抛出了错误。已删除服务层中的app.config,并解决了问题。