我有一个WorkflowServiceHost我在Windows服务中启动.一切正常,但一段时间后服务停止响应请求.通过跟踪日志,我可以看到抛出异常 - 在这种情况下是通过简单加载元数据页面 - 关于被中止的通信对象:
The communication object, System.ServiceModel.Channels.TransportReplyChannelAcceptor+TransportReplyChannel, cannot be used for communication because it has been Aborted.
Run Code Online (Sandbox Code Playgroud)
跟踪文件中没有指示问题的先前日志.我们每分钟监控它以确保它正在运行(因为出现此问题)并且我可以在元数据页面突然开始报告它处于中止状态之前看到许多成功的请求.
此时恢复的唯一方法是重启我的服务.我以前曾多次使用WCF,但从未作为WF的前端.我之前从未遇到过我的WCF服务这个问题,WorkflowServiceHost会发生什么事情?
谢谢!
更新:
以下是WCF的一些跟踪日志:

我的代码调用了当前未运行的WCF服务。所以我们应该期待EndPointNotFoundException。using语句尝试对Close()导致a的异常连接进行故障处理CommunicationObjectFaultedException。在use块周围的try catch块中捕获了此异常:
class Program
{
static void Main()
{
try
{
using (ChannelFactory<IDummyService> unexistingSvc = new ChannelFactory<IDummyService>(new NetNamedPipeBinding(), "net.pipe://localhost/UnexistingService-" + Guid.NewGuid().ToString()))
{
using (IClientChannel chan = (unexistingSvc.CreateChannel() as IClientChannel))
{
(chan as IDummyService)?.Echo("Hello");
}
}
}
catch (EndpointNotFoundException ex)
{
Console.WriteLine("Expected");
}
catch (CommunicationObjectFaultedException ex)
{
Console.WriteLine("Expected: caused by closing channel that has thrown EndPointNotFoundException");
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意,服务EndPoint使用新的Guid,因此它将永远不会监听服务。
IDummyService 是:
[ServiceContract]
interface IDummyService
{
[OperationContract]
string Echo(string e);
}
Run Code Online (Sandbox Code Playgroud)
这会导致Visual Studio调试器(Visual Studio Professional …
据我所知,每当我实例化一个实现IDisposable的类时,我都应该使用该using关键字以确保它被正确处理掉.
像这样:
using (SecureString s = new SecureString())
{
}
Run Code Online (Sandbox Code Playgroud)
以上内容对我来说很容易理解 - 我可以s在这些括号内使用但是一旦我离开这些括号,我就再也不能参考了s.范围很容易看到.
但我不明白的是当你使用using没有封闭括号时它是如何工作的.
private void Function()
{
// Some code here
using (SecureString s = new SecureString())
// more code here
}
Run Code Online (Sandbox Code Playgroud)
你根本不需要使用括号...所以...如果using关键字没有括号,我怎么知道我能在哪里使用这个对象以及它在哪里处理?
在我们的项目中,我们使用以下代码进行WCF调用.
// In generated Proxy we have..
public static ICustomer Customer
{
get
{
ChannelFactory<ICustomer> factory = new ChannelFactory<ICustomer>("Customer");
factory.Endpoint.Behaviors.Add((System.ServiceModel.Description.IEndpointBehavior)new ClientMessageInjector());
ICustomer channel = factory.CreateChannel();
return channel;
}
}
Run Code Online (Sandbox Code Playgroud)
我们有Service Proxy类,它有类似的方法
public static Datatable GetCustomerDetails(int id)
{
return Services.Customer.GetCustomerDetails(id);
}
public static void .SaveCustomerDetails (int id)
{
Services.Customer.SaveCustomerDetails(id) ;
}
Run Code Online (Sandbox Code Playgroud)
等...我们用来打电话.
最近我们发现我们需要"关闭"wcf连接,我们正试图找出去做而不要求我们的开发人员改变他们的代码太多.
请向我们提供一些有助于我们实现这一目标的建议