J'ai une question à propos de l'utilisation du framework AddIn, fourni par .NET Framework (utilise actuellement 3.5 SP1) implémenté dans l'espace de noms System.AddIn. Je construis un prototype avec AddIn simple. Cet AddIn est instancié dans la logique métier du service WCF.System.AddIn dans WCF
mise en œuvre de la logique métier (uniquement le code nécessaire est affiché):
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!");
}
...
}
La mise en œuvre du service (uniquement le code nécessaire est affiché):
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);
}
...
}
J'ai créé deux tests unitaires. Une méthode directe d'appel de la logique métier, une autre méthode WCF. appel direct fonctionne très bien, mais si je AddIn de WCF activer i obtenir cette exception:
« Impossible de lancer proxy transparent taper 'ERES.ConversionService.Contract.IConversionContract'
Trace de la pile:
à ConversionHostViewToContractAdapter_ConstructorInvoker (Object) à System.AddIn.Hosting.AddInActivator.AdaptToHost [T] (de pipeline AddInToken, IContract addInContract) à System.AddIn.Hosting.AddInActivator.ActivateInAppDomain [T] (pipeline AddInToken, domaine AppDomain, AddInControllerImpl contro ller, boolean weOwn) à System.AddIn.Hosting.AddInActivator.Activate [T] (jeton AddInToken, permissionSet permissionSet, String appDomainName) à System.AddIn.Hosting.AddInActivator.Activate [T] (jeton AddInToken, niveau AddInSecurityLevel, chaîne appDomainName) à System.AddIn.Hosting.AddInActivator.Activate [T] (jeton de AddInToken, niveau AddInSecurityLevel) à System.AddIn.Hosting.AddInToken.Activate [T] (AddInSecurityLevel trustLevel) à ERES.ConversionService.BL. BusinessLayer.Execute (Object toConvert, opération Operation) dans C: \ Documents and Settings \ kc \ Mes documents \ Visual Studio 2008 \ Projects \ ConversionServiceSolution \ ERES.ConversionService.BL \ BusinessLayer.cs: ligne 44 à ERES.ConversionService.Service .Execute (Object toConvert, opération Operation) dans C: \ Documents and Settings \ kc \ Mes documents \ Visual Stud io 2008 \ Projects \ ConversionServiceSolution \ ERES.ConversionService \ Service.svc.cs: ligne 25 à SyncInvokeExecute (Object, Object [], Object []) à System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke (instance d'objet, Object [ ] entrées, objet [] & sorties) à System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin (MessageRpc & rpc)
Toute aide?
Cordialement Anton Kalcik
MISE À JOUR: j'ai pu contourner ce avec ce code:
ConversionHostView view = token.Value.Activate<ConversionHostView>(AppDomain.CurrentDomain);
Donc, à ce cas est seulement possible d'exécuter AddIn seulement au même AppDomain que service auto. Mais je ne comprends pas pourquoi?
Désolé mais je n'ai plus le code car c'était un prototype et il y a 2 ans. Je vous remercie. –