0

I am somewhat new to WCF and I am running into a very simple design issue which I assume has well-established answers. I created a (single-instance) main application that does all the 'business logic': connects to a database and a third-party API, executes admin user commands etc. This application is meant to be run on a server machine, and my next step is to create a WcfServiceLibrary on top so that end-users can execute commands remotely using Wcf clients.

Logically the WcfServiceLibrary makes a reference to the main application assembly. Call me naive but I thought this would let me access the main application objects and methods. Well it does but by creating a duplicate of the main application within the WcfServiceLibrary process, which is a no-go. (I also discovered that when accessed from within the WcfServiceLibrary a single-instance application is being duplicated!)

How to resolve this issue? So far I am thinking of the following:

  • Self-host the Wcf service within the main application: possible but I would be losing the clean separation between 'business logic' and service logic
  • Use IPC techniques to communicate between main application and WcfSrviceLibrary: this looks like an overkill as it creates another layer of server-client interface (except perhaps if I use out-of-process COM)
  • Any other way?

Thanks in advance for your help! I want to believe there's a simple solution to this problem round the corner...!

Community
  • 1
  • 1
phaedo
  • 123
  • 1
  • 6
  • Extract all logic into separate assembly, reference this assembly from both your main application and your wcf service? – Evk Sep 11 '16 at 18:18
  • @Evk Such assembly would still be loaded twice: once for the main app running on the server, and a second (or more) time whenever the Wcf service is instantiated. What I need is the Wcf service accessing the main app without duplicating it internally. – phaedo Sep 11 '16 at 20:09
  • If you are on server, why you need some main app? Why not just use only wcf service? – Evk Sep 11 '16 at 20:31
  • The main app maintains a central database and an API connection with third-party software. As I wrote it is possible to self-host the wcf service within the main app if there is no other option. – phaedo Sep 11 '16 at 21:58

1 Answers1

0

This Might be what you are looking for ...

public static class RealAppCoreHelper
{
    private static RealAppCoreObject m_GlobalAppInstance = null;

    public static RealAppCoreObject GetGlobalMainInstance()
    {
        // return the one and only instance of our main app

        if (m_GlobalAppInstance == null)
        {
            m_GlobalAppInstance = new RealAppCoreObject();
        }

        return m_GlobalAppInstance;
    }
}

You could put this logic in the WCF wrapping app or your main app depending on the exact behavior you are looking for.

Sql Surfer
  • 1,344
  • 1
  • 10
  • 25
  • This would create a duplicate instance of the main app within the WcfServiceLibrary. Remember that the main app is running on the server before the WcfServiceLibrary is called to host the service. – phaedo Sep 11 '16 at 20:06