开发者

Architecture for remoting to call a Windows Service method

I have added remoting calls to my Windows Service so my GUI application can talk to it. It works great, but my channel implementation has no knowledge of my service.

How should I layer my classes so that my remoting channel implementation can call methods in my service class?

Channel Interface:

public interface IMyService
{
    string Ping();
    string SomeMethod(string input);
}

Channel Implementation:

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";
    }
}

Service Class

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());
        }
    }
}

How should I structure my classes so that my chann开发者_StackOverflowel can call my service methods?


In this case you should use WCF. WCF replaces .net remoting.

If both your client and service are on the same machine you can use named pipes binding.

If they are on different machines you can use net tcpip binding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜