如何修复“的类型初始值设定项引发异常” [WCF]

时间:2019-02-07 14:31:36

标签: c# wcf exception

我的解决方案中有一个WCF应用程序和一些客户端。问题是什么-当我尝试从客户端访问服务中实现的任何方法时,都会出现此错误。我正确地将服务引用添加到每个客户端,并且我的Web.config文件如下所示。 我已经在我的Web配置文件中包含了详细的异常,然后,我不断收到此错误。

我已经尝试调试我的代码,看看哪一部分引发异常,但是当我运行客户端时会发生这种情况,并且错误在服务器端。问题可能出在服务器类的静态构造函数中吗?

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
       </system.web>
  <system.serviceModel>
    <services>
      <service name="Service.Service" behaviorConfiguration="debug">

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

        <endpoint address="AlarmDisplay" binding="wsDualHttpBinding" contract="Service.IAlarm"></endpoint>
        <endpoint address="AlarmDisplay/Mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

        <endpoint address="DatabaseManager" binding="basicHttpBinding" contract="Service.IDatabaseManager"></endpoint>
        <endpoint address="DatabaseManager/Mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

        <endpoint address="RealTimeUnit" binding="basicHttpBinding" contract="Service.IRealTimeUnit"></endpoint>
        <endpoint address="RealTimeUnit/Mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

        <endpoint address="Trending" binding="wsDualHttpBinding" contract="Service.ITrending"></endpoint>
        <endpoint address="Trending/Mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>    
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata/>
        </behavior>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

这是服务文件:

public class Service : IAlarm, IDatabaseManager, IRealTimeUnit, ITrending
   {
    static Dictionary<string, Tag> tags = new Dictionary<string, Tag>();
    static Dictionary<string, Thread> threads = new Dictionary<string, Thread>();

    static SimulationDriver simulationDriver = new SimulationDriver();
    static RealTimeDriver realTimeDriver = new RealTimeDriver();

    static IAlarmCallback alarmCallback = null;
    delegate void AlarmDelegate(string message);
    static event AlarmDelegate AlarmActivated = null;

    static ITrendingCallback trendingCallback = null;
    delegate void TrendingDelegate(int option, string type, string ID, double value);
    static event TrendingDelegate ValueChanged = null;

    static string scadaDirectory = @"C:\Users\Sevic\Desktop\SCADA\dir\";
    static string configFile = @"scadaConfig.txt";
    static string alarmFile = @"alarmLog.txt";

    static string database = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Sevic\Desktop\SCADA\SCADA\Service\App_Data\DATABASE.mdf;Integrated Security=True";
    static SqlConnection connection = new SqlConnection(database);

    static bool serviceRunning = LoadConfigFile();

 ... implementation of methods
    }

0 个答案:

没有答案