我有一台Windows服务,我需要在计算机上安装并运行足够长的时间来发送日志电子邮件然后再睡24小时。如果我从Web客户端调用服务方法,它工作正常,但是当我从Windows服务调用它时,它每次都会失败,并且错误信息没有给我任何特定的调查信息:
通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态。
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
上任何建议都将不胜感激。谢谢。
答案 0 :(得分:1)
解决。我删除了所有的try / catch,并在错误消息中提供了更多描述信息
答案 1 :(得分:0)
由于客户端代理对象周围的使用块,您可能遇到了问题。请参阅此文章:http://msdn.microsoft.com/en-us/library/aa355056.aspx
调用处理客户端代理对象可能会掩盖基础异常。