'System.ServiceModel.Diagnostics.TraceUtility'在WCF中引发了异常

Kus*_*ima 3 c# wcf

我是WCF的新手,我正在通过创建示例应用程序进行自学.这是一个非常简单的应用程序的代码,它会在注释下面的行后面抛出一个异常形式

namespace ConsoleAppHost
{
    class Program
    {
        public static void Main()
        {    
            //Exception thorwing from following line
            using (ServiceHost host = new ServiceHost(typeof(ReportService.ReportService))) //Exception thorwn from this
            {
                host.Open();
                Console.WriteLine("Host started @ " + DateTime.Now.ToShortDateString());
                Console.ReadLine();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的app.config文件来自主机(相同的控制台应用程序).请善意告诉我问题在哪里?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <services>
    <service name="ReportService.ReportService" behaviorConfiguration="mexBehavior">
      <endpoint address="ReportService" binding="netTcpBinding" bindingconfiguration="" contract="ReportService.IReportService"></endpoint>
      <host>
        <baseAddresses>
          <add baseAddress ="http://localhost:8080/"/>
          <add baseAddress ="net.tcp://localhost:8090/"/>
        </baseAddresses>
      </host>
    </service>
  </services>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果您真的感兴趣,请查看以下源代码.

https://onedrive.live.com/redir?resid=F1C4404429DCCB7F!17480&authkey=!ABb-N4DexoIFGqw&ithint=file%2czip

谢谢.

Igo*_*tin 6

您的代码有两个问题.

  1. 的位置<services>配置文件中的部分:它是里面<system.serviceModel>.
  2. bindingconfiguration属性拼写错误.一定是bindingConfiguration.

以下是您可以找到它的方法:实际上,您指出的行会抛出异常.这是TypeInitializationException.如果深入InnerException查看字段,则最终可以看到"无法识别的属性"等简单消息.