的类型初始“Sys​​tem.ServiceModel.Diagnostics.TraceUtility” [英] The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility'

查看:634
本文介绍了的类型初始“Sys​​tem.ServiceModel.Diagnostics.TraceUtility”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用来自一个C#/。NET控制台应用程序的WCF服务这个错误:

  

的类型初始System.ServiceModel.Diagnostics.TraceUtility引发了异常。

的InnerException:

  {配置系统初始化失败}
 {无法识别的配置节system.serviceModel / serviceBehaviors。
  (C:\\用户\\ \\ ... \\文件的Visual Studio 2013 \\ \\项目\\ Test.Console
   Test.Console \\ \\斌调试\\ Test.Console.vshost.exe.Config 7号线)}
 

WebConfig:

< XML版本=1.0编码=UTF-8&GT?; <结构>    <的ConnectionStrings>     <添加名称=ServiceConnString          的providerName =System.Data.SqlClient的          的connectionString =服务器=;数据库= TestDB的; Trusted_Connection = TRUE;/>   < /的ConnectionStrings>   < system.serviceModel>     < serviceBehaviors>       <行为NAME =调试>         < serviceDebug includeExceptionDetailInFaults =真/>       < /行为>     < / serviceBehaviors>     <绑定>       < basicHttpBinding的>         <绑定名称=basicHttpBinding的closeTimeout =00:01:00                  openTimeout =00:01:00receiveTimeout =00:10:00                  的SendTimeout =00:01:00allowCookies =假                  bypassProxyOnLocal =假                  hostNameComparisonMode =StrongWildcard                  maxBufferSize =20000000maxBufferPoolSize =524288                  maxReceivedMessageSize =20000000messageEncoding =文本                  textEncoding =UTF-8transferMode =缓冲                  useDefaultWebProxy =真正的>           < readerQuotas MAXDEPTH =32maxStringContentLength =8192                         maxArrayLength =16384maxBytesPerRead =4096                         maxNameTableCharCount =16384/>           <安全模式=无>           < /安全>         < /装订>       < / basicHttpBinding的>     < /绑定>     <客户端>       <端点地址=HTTP://本地主机:26576 / PersonInfoService.svc                 合同=PersonInfoService.IPersonInfoService                 绑定=basicHttpBinding的NAME =basicHttpBinding的/>     < /客户>   < /system.serviceModel>   <启动>     < supportedRuntime版本=4.0版的SKU =NETFramework,版本= V4.5/>   < /启动> < /结构>

解决方案

您的配置文件丢失的行为的标签,这需要打包serviceBehaviors。

<行为>  < serviceBehaviors>   <行为NAME =调试>     < serviceDebug includeExceptionDetailInFaults =真/>   < /行为>  < / serviceBehaviors> < /行为>

I got this error while trying to consume a WCF service from a C#/.NET console application:

The type initializer for System.ServiceModel.Diagnostics.TraceUtility threw an exception.

InnerException:

{"Configuration system failed to initialize"}
 {"Unrecognized configuration section system.serviceModel/serviceBehaviors.
  (C:\\Users\\...\\Documents\\Visual Studio 2013\\Projects\\Test.Console\\
   Test.Console\\bin\\Debug\\Test.Console.vshost.exe.Config line 7)"}

WebConfig:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <connectionStrings>
    <add name="ServiceConnString" 
         providerName="System.Data.SqlClient" 
         connectionString="Server=.;Database=TestDB;Trusted_Connection=True;"/>
  </connectionStrings>
  <system.serviceModel>
    <serviceBehaviors>
      <behavior name="debug">
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding" closeTimeout="00:01:00" 
                 openTimeout="00:01:00" receiveTimeout="00:10:00" 
                 sendTimeout="00:01:00" allowCookies="false" 
                 bypassProxyOnLocal="false" 
                 hostNameComparisonMode="StrongWildcard" 
                 maxBufferSize="20000000" maxBufferPoolSize="524288" 
                 maxReceivedMessageSize="20000000" messageEncoding="Text" 
                 textEncoding="utf-8" transferMode="Buffered" 
                 useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                        maxArrayLength="16384" maxBytesPerRead="4096"
                        maxNameTableCharCount="16384"/>
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:26576/PersonInfoService.svc" 
                contract="PersonInfoService.IPersonInfoService" 
                binding="basicHttpBinding" name="BasicHttpBinding"/>
    </client>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

解决方案

Your configuration file is missing the "behaviors" tag, which needs to wrap "serviceBehaviors".

<behaviors>
 <serviceBehaviors>
  <behavior name="debug">
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>
 </serviceBehaviors>
</behaviors>

这篇关于的类型初始“Sys​​tem.ServiceModel.Diagnostics.TraceUtility”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆