System.AddIn in WCF

I have a question about using the AddIn framework provided by the .NET Framework (currently using 3.5 SP1) implemented in the System.AddIn namespace. I am creating a prototype with a simple AddIn. This AddIn is created in the WCF service business logic.

Implementation of business logic (only the necessary code is displayed):

internal class BusinessLayer : IBusinessLayer
{
    public object Execute(object toConvert, Operation operation)
    {
        IDictionary<string, AddInToken> tokens = AddIns.Store.GetAddInsTokens(@"c:\SomePathToStore");

        foreach (KeyValuePair<string, AddInToken> token in tokens)
        {
            if (operation.Name == token.Key && operation.Version == token.Value.Version)
            {
                ConversionHostView view = token.Value.Activate<ConversionHostView>(AddInSecurityLevel.FullTrust);

                object converted =  view.Convert(toConvert);

                AddInController.GetAddInController(view).Shutdown();

                return converted;
            }
        }

        throw new InvalidOperationException("No operation found!");
    }
    ...
}

Service execution (only the required code is displayed):

public class Service : IServiceContract
{
    IBusinessLayer bl;

    public Service()
    {
        bl = BL.BLFactory.GetBL();
    }

    public object Execute(object toConvert, ERES.ConversionService.Entity.Operation operation)
    {
        return bl.Execute(toConvert, operation);
    }
    ...
}

I created two unit tests. One method to directly invoke business logic, another WCF method. The direct call works fine, but if I activate AddIn from WCF, I get this exception:

"Could not pass transparent proxy for input" ERES.ConversionService.Contract.IConversionContract "

Stack trace:

ConversionHostViewToContractAdapter_ConstructorInvoker ()   System.AddIn.Hosting.AddInActivator.AdaptToHost [T] (AddInToken , IContract addInContract)   System.AddIn.Hosting.AddInActivator.ActivateInAppDomain [T] ( AddInToken, AppDomain, AddInControllerImpl, weOwn)   System.AddIn.Hosting.AddInActivator.Activate [T] (AddInToken token, PermissionSet permissionSet, String appDomainName)   System.AddIn.Hosting.AddInActivator.Activate [T] ( AddInToken, AddInSecurityLevel, String appDomainName)   System.AddIn.Hosting.AddInActivator.Activate [T] ( AddInToken, AddInSecurityLevel)   System.AddIn.Hosting.AddInToken.Activate [T] (AddInSecurityLevel trustLevel)   ERES.ConversionService.BL.BusinessLayer.Execute(Object toConvert, Operation operation) C:\Documents and Settings\kc\ \Visual Studio 2008\Projects\ConversionServiceSolution\ERES.ConversionService.BL\BusinessLayer.cs: 44   ERES.ConversionService.Service.Execute(Object toConvert, Operation operation) C:\Documents and Settings\kc\ \Visual Studio 2008\Projects\ConversionServiceSolution\ERES.ConversionService\Service.svc.cs: 25   SyncInvokeExecute (Object, Object [], Object [])   System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke( , Object [] , Object [] )   System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc & rpc)

?

UPDATE: :

ConversionHostView view = token.Value.Activate<ConversionHostView>(AppDomain.CurrentDomain);

, AddIn AppDomain, . , ?

+3
1

, , .

, MEF , .

?

0

Source: https://habr.com/ru/post/1710751/


All Articles