1

SOAP の代わりに REST を使用して WCF ワークフロー サービス アプリケーションを呼び出す方法が必要です。カスタム webhttpbehavior で REST エンドポイントを定義しました。その呼び出しから、XAMLX を読み込んで実行しようとしています。

私の最初の試みは失敗します


    Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled

ワークフローを呼び出す前に Expression をコンパイルするコードを見つけたところ、次のようなエラーが発生しました。


    The type or namespace name 'Activities' does not exist in the namespace 'System'

設定する他のコードを見つけました

 AttachableMemberIdentifier and AttachablePropertyServices

それから私は得た

The type or namespace name 'Activities' does not exist in the namespace 'System.ServiceModel'

3 つすべての名前空間 (私のローカル ソリューション、System.ServiceModel および System.Activities) のアセンブリ参照を追加していますが </p>

xamlx は、GetData が int を渡して生成し、int.ToString() を返す単純なすぐに使えるものです。

何が欠けていますか?

次のコード:


    namespace WFStarterSolution
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class RestService
    {

        static void CompileExpressions(DynamicActivity activity)
        {
            var activityName = activity.Name;

            // Split activityName into Namespace and Type.Append _CompiledExpressionRoot to the type name
            // to represent the new type that represents the compiled expressions.
            // Take everything after the last . for the type name.
            var activityType = activityName.Split('.').Last() + "_CompiledExpressionRoot";
            // Take everything before the last . for the namespace.
            var activityNamespace = string.Join(".", activityName.Split('.').Reverse().Skip(1).Reverse());

            // Create a TextExpressionCompilerSettings.
            var settings = new TextExpressionCompilerSettings
            {
                Activity = activity,
                Language = "C#",
                ActivityName = activityType,
                ActivityNamespace = activityNamespace,
                RootNamespace = null,//"CSharpExpression",
                GenerateAsPartialClass = false,
                AlwaysGenerateSource = true,
                ForImplementation = true
            };

            // Compile the C# expression.
            var results = new TextExpressionCompiler(settings).Compile();

            // Any compilation errors are contained in the CompilerMessages.
            if (results.HasErrors)
            {               
                var cm = results.CompilerMessages.Aggregate(" 
", (current, e) => current + (e.Number + " - "+e.Message + " : Line Number "+e.SourceLineNumber + "
")); throw new Exception("Compilation failed."+cm); } // Create an instance of the new compiled expression type. var compiledExpressionRoot = Activator.CreateInstance(results.ResultType, new object[] { activity }) as ICompiledExpressionRoot; // Attach it to the activity. CompiledExpressionInvoker.SetCompiledExpressionRoot( activity, compiledExpressionRoot); } [OperationContract] public string DoWork() { // call WFService XAMLX somehow var filepath = AppDomain.CurrentDomain.BaseDirectory; try { var serviceImplementation = XamlServices.Load(filepath + "WFService.xamlx"); var service = serviceImplementation as WorkflowService; if (service == null) { return "Failed"; } else { var activity = service.Body; var operand1 = new InArgument(); var dyanamicActivity = new DynamicActivity { Name = "WFServiceName", Implementation = () => activity}; var p = new DynamicActivityProperty { Name = "data", Type = typeof(InArgument), Value = operand1 }; dyanamicActivity.Properties.Add(p); var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); var namespaces = new List { "WFStarterSolution" }; var ar = new[] { new AssemblyReference { Assembly = typeof (DynamicActivity).Assembly }, new AssemblyReference { Assembly = typeof (RestService).Assembly }, new AssemblyReference { Assembly = typeof (ServiceContractAttribute).Assembly } }; TextExpression.SetReferencesForImplementation(dyanamicActivity, ar); AttachablePropertyServices.SetProperty(dyanamicActivity, impl, namespaces); CompileExpressions(dyanamicActivity); var iDict = new Dictionary() { { "data", 45} }; var output = WorkflowInvoker.Invoke(dyanamicActivity, iDict); return "success"; } } catch (Exception ex) { return ex.Message+"
"+ex.StackTrace; } } } }

UPDATE * 以下を AssemblyReference 配列に追加すると


,new AssemblyReference 
{
    Assembly = typeof (WorkflowService).Assembly
}

、それはうまくコンパイルされます...しかし、それでも元のエラーが発生します


    Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled
4

0 に答える 0