包含 NServiceBus 和 WCF 的配置文件失败

发布于 2024-11-18 14:56:00 字数 2685 浏览 2 评论 0原文

我无法弄清楚下面的配置代码有什么问题,当我包含 NServiceBus 配置信息时,出现以下错误:

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

当我注释掉时,该消息消失了NServiceBus 代码,因此它与 .net 框架的错误安装无关,就像一些互联网建议的那样。

任何想法将不胜感激!

当我的代码到达以下几点的 WebClient 构造函数

WEBCallback = new CFPWebImplementation();
WEBContext = new InstanceContext(WEBCallback);
WEBClient = new TradeOperationsClient(WEBContext);

和我的配置文件时,会导致错误:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ITradeOperations" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8687/TradePortal/Operations/"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITradeOperations"
          contract="CFP_Web.ITradeOperations" name="NetTcpBinding_ITradeOperations" />
    </client>
  </system.serviceModel>



  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
  </configSections>
  <MsmqTransportConfig InputQueue="HammersmithInputQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="Messages" Endpoint="BBRGInputQueue"/>
    </MessageEndpointMappings>
  </UnicastBusConfig>
   <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

I cant figure out whats wrong with my config code below, when I include the NServiceBus config info I get the followng error:

The Type Initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception'

The message goes away when I comment out the NServiceBus code so its not related to a faulted instal of the .net framework like some of the interwebs suggested.

Any ideas would be appreciated!

The error is caused when my code gets to the constructor for WebClient belowfollowing point:

WEBCallback = new CFPWebImplementation();
WEBContext = new InstanceContext(WEBCallback);
WEBClient = new TradeOperationsClient(WEBContext);

and my config file:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ITradeOperations" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8687/TradePortal/Operations/"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITradeOperations"
          contract="CFP_Web.ITradeOperations" name="NetTcpBinding_ITradeOperations" />
    </client>
  </system.serviceModel>



  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
  </configSections>
  <MsmqTransportConfig InputQueue="HammersmithInputQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="Messages" Endpoint="BBRGInputQueue"/>
    </MessageEndpointMappings>
  </UnicastBusConfig>
   <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2024-11-25 14:56:00

结果答案是,需要成为 app.config 文件中的第一个元素

Turns out the answer was that the needs to be the first element in the app.config file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文