none
Sharing Methods Imported using MEF in WCF Client Service RRS feed

  • Question

  • Hi

    I am using the following code to successfully load a plugin in my WCF client service main class:

            [Import]
            public IBasePluginService PluginService { get; set; }

                

            public void PluginCompose(string targetPath)
            {
                var catalog = new DirectoryCatalog(targetPath);
                var container = new CompositionContainer(catalog);
                container.ComposeParts(this);
            }

    And call a method using:

    PluginCompose(loadPluginTarget);
    PluginService.HelloWorld("Something");

    How do I make the plugin dll methods available in the class which implements callback interface of the duplex contract?

    Do I need call PluginCompose() everytime before calling a method in my plugin dll?

    • Moved by Eason_H Tuesday, August 27, 2013 1:51 AM
    Monday, August 26, 2013 3:02 AM

Answers

  • Hi RobNZ,

    So you have some MEF plugin components (encapsulated in separate dll) which you want to expose from your WCF client to service-side (via callback channel), correct?

    If so, I think there are two main things you need to think about:

    1) When you invoke a WCF service supporting duplex/callback channel, you need to supply a callback interface instance at client-side (via the proxy class's constructor). So if you want the callback instance to carry the functionality from the plugin objects, you need to call "container.ComposeParts" against the callback instance. e.g.

    var cbInstance = new InstanceContext(new CallbackHandler());
    
    container.ComposeParts(cbInstance);
    

    Thus, the certain plugin [Import] member on the CallbackHandler class will be filled.

    2) In order to let the server-side service to consume the client-side plugin related functions, you need to expose the function via some methods on your CallbackHandler instance. And this should be done via declaring additional operations on the Callback contract.

    Or if you do not want to make particular change on the callback contract, then the client-side can just encapsulate all the code logic at client-side (invoke plugin methods at client-side code) and the server-side just invoke operations on the callback Contract interface without knowing anything about the plugin components at client-side.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by RobNZ Wednesday, August 28, 2013 8:32 PM
    Wednesday, August 28, 2013 3:43 AM
    Moderator

All replies

  • You should post to the MSDN WCF forum for help.
    Monday, August 26, 2013 10:04 AM
  • Hi RobNZ,

    This forum is to discuss problems of C# development. I will move it to WCF forum for more efficient responses.

    Thanks.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, August 27, 2013 1:48 AM
  • Hi RobNZ,

    So you have some MEF plugin components (encapsulated in separate dll) which you want to expose from your WCF client to service-side (via callback channel), correct?

    If so, I think there are two main things you need to think about:

    1) When you invoke a WCF service supporting duplex/callback channel, you need to supply a callback interface instance at client-side (via the proxy class's constructor). So if you want the callback instance to carry the functionality from the plugin objects, you need to call "container.ComposeParts" against the callback instance. e.g.

    var cbInstance = new InstanceContext(new CallbackHandler());
    
    container.ComposeParts(cbInstance);
    

    Thus, the certain plugin [Import] member on the CallbackHandler class will be filled.

    2) In order to let the server-side service to consume the client-side plugin related functions, you need to expose the function via some methods on your CallbackHandler instance. And this should be done via declaring additional operations on the Callback contract.

    Or if you do not want to make particular change on the callback contract, then the client-side can just encapsulate all the code logic at client-side (invoke plugin methods at client-side code) and the server-side just invoke operations on the callback Contract interface without knowing anything about the plugin components at client-side.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by RobNZ Wednesday, August 28, 2013 8:32 PM
    Wednesday, August 28, 2013 3:43 AM
    Moderator