C# 作为WCF服务的线程

C# 作为WCF服务的线程,c#,wcf,service,C#,Wcf,Service,我有一个Windows服务,我需要安装在一台机器上,运行足够长的时间来发送一封日志电子邮件,然后睡24小时。如果我从web客户端调用服务方法,它可以正常工作,但当我从windows服务调用它时,每次都会失败,错误信息也不会给我任何具体的调查信息: 通信对象System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态 public partial class EDBDailyLogMailer : ServiceBase { T

我有一个Windows服务,我需要安装在一台机器上,运行足够长的时间来发送一封日志电子邮件,然后睡24小时。如果我从web客户端调用服务方法,它可以正常工作,但当我从windows服务调用它时,每次都会失败,错误信息也不会给我任何具体的调查信息:

通信对象System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态

 public partial class EDBDailyLogMailer : ServiceBase
 {
    Thread thread;

    public EDBDailyLogMailer()
    {
        InitializeComponent();
        this.ServiceName = "EDB Daily Log Mailer";
    }

    protected override void OnStart(string[] args)
    {
        try
        {
            thread = new Thread(MailLogDaily);
            thread.Start();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    static void MailLogDaily()
    {
        while (true)   
        {
            try
            {
                using (ApprovableFieldClient client = new ApprovableFieldClient())
                    client.EmailEventLog();
                Thread.Sleep(86400000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
EmailEventLog()中的代码在从其他地方调用时工作正常,因此我不会发布该代码。以下是App.config中的我的端点:

 <system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="ExperienceServiceBinding" maxReceivedMessageSize="1048576" maxBufferSize="1048576"/>
  </netTcpBinding>
</bindings>
<client>
  <endpoint bindingConfiguration="ExperienceServiceBinding" address="net.tcp://bosvc01:1125/ApprovableFieldService" binding="netTcpBinding" contract="Ropes.Experience.Administration.Contracts.Services.IApprovableFieldService">
    <identity>
      <servicePrincipalName value="firstname.lastname@somecompany.com"/>
    </identity>
  </endpoint>
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="Ropes.Experience.Administration.Managers.ApprovableFieldManagerBehavior">
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

ApprovableFieldClient的服务托管在bosvc01:1125上


如有任何建议,将不胜感激。谢谢。

您可能遇到问题,因为在客户端代理对象周围使用了块。见本文:


释放客户端代理对象的调用可能会屏蔽底层异常。

由于客户端代理对象周围的使用块,您可能遇到问题。见本文:


释放客户端代理对象的调用可能会屏蔽底层异常。

已解决。我删除了所有的try/catch,并在错误消息中获得了更多描述信息。我删除了所有的try/catch,并在错误消息中获得了更多的描述信息