2016-02-13 67 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

謝謝。如你所述,在我做了修改之後它就起作用了。再次感謝給我更多細節。它們對我來說非常重要。 –