【发布时间】:2010-11-24 06:58:03
【问题描述】:
我已将远程调用添加到我的 Windows 服务,以便我的 GUI 应用程序可以与之通信。效果很好,但我的频道实现不了解我的服务。
我应该如何分层我的类,以便我的远程通道实现可以调用我的服务类中的方法?
频道接口:
public interface IMyService
{
string Ping();
string SomeMethod(string input);
}
渠道实施:
public class MyServiceChannel : MarshalByRefObject, IMyService
{
public string Ping()
{
return "Pong";
}
public string SomeMethod(string input)
{
MethodForChannelToCall(input); // in Service class. How to reference?
return "Some Output";
}
}
服务类
class MyService : ServiceBase
{
public void MethodForChannelToCall(string input)
{
// do service stuff for remoting call
}
public MyService()
{
// Set up remoting channel
try
{
TcpChannel tcpChannel = new TcpChannel(12345);
ChannelServices.RegisterChannel(tcpChannel, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyServiceChannel),
"MyServiceChannel",
WellKnownObjectMode.SingleCall);
// Should I pass an instance of my service to my channel somehow here?
}
catch (Exception ex)
{
this.EventLog.WriteEntry("Remoting error: " + ex.ToString());
}
}
}
我应该如何构建我的类,以便我的频道可以调用我的服务方法?
【问题讨论】:
-
或者我应该在 WCF 中使用管道?
-
我不精通 Windows 服务,但我认为 Windows 服务不是这样工作的,或者是这样吗?
-
发现这个问题描述了使用 WCF 的类似问题:stackoverflow.com/questions/3066519/wcf-named-pipe-ipc
标签: c# architecture windows-services remoting