c# - 'System.ServiceModel.Diagnostics.TraceUtility' 在 WCF 中抛出异常

标签 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();
            }
        }
    }
}

这是来自主机(同一个控制台应用程序)的我的 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>

这里是源码,有兴趣的可以看看。

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

谢谢。

最佳答案

您的代码有两个问题。

  1. <services> 的位置配置文件中的部分:它必须在 <system.serviceModel> 内.
  2. bindingconfiguration属性拼写错误。必须是 bindingConfiguration .

这是您可以找到的方法:确实在您指出的那一行抛出了异常。这是 TypeInitializationException .如果您深入了解 InnerException字段,然后您终于可以看到像“无法识别的属性”这样的纯文本消息。

关于c# - 'System.ServiceModel.Diagnostics.TraceUtility' 在 WCF 中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35381090/

相关文章:

c# - 如何使整数的子集相等?

wcf - 调试时如何从 WCF 服务内部查看控制台输出?

c# - 如何检查给定日期是否存在于月份?

c# - 尾数介于 0 和 1 之间的科学计数法的 .NET 格式说明符

asp.net - WCF 请求处理线程敏捷吗?

c# - 通过 Web 代理与 WCF 服务通信;从 Windows 服务中

wcf - WebServiceHostFactory 和 IIS 身份验证

wcf - 如何开启WCF跟踪?

c# - 将当前的单元测试结果与之前的进行比较

c# - OneDrive 下载 .sdf 文件后的本地数据库 "no format for SQL server Compact"