2016-02-13 121 views
2

我是WCF的新手,我正在通过创建示例应用程序进行自学。这是一个非常简单的应用程序,它抛出一个异常形式以下线,注释'System.ServiceModel.Diagnostics.TraceUtility'在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

谢谢。

回答

5

您的代码有两个问题。

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

下面是你可以找到的方法:事实上,在你指出的那条线上抛出异常。这是TypeInitializationException。如果您深入了解InnerException字段,那么您终于可以看到简单的消息,如“无法识别的属性”。

+0

谢谢。如你所述,在我做了修改之后它就起作用了。再次感谢给我更多细节。它们对我来说非常重要。 –