WF 4.5 WCF Workflow Service Application calling with REST
Want a way to call a WCF Workflow Service Application using REST instead of SOAP. I've defined a REST endpoint with custom webhttpbehavior and from that call I am trying to load the XAMLX and run it.
My first attempt fails with
Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled
I found code to compile the Expression before invoking the workflow and then I get errors like.
The type or namespace name 'Activities' does not exist in the namespace 'System'
I found some other code to set
AttachableMemberIdentifier and AttachablePropertyServices
then I got
The type or namespace name 'Activities' does not exist in the namespace 'System.ServiceModel'
Even though I'm adding the assemblyreferences for all 3 namespaces (my local solution, System.ServiceModel and System.Activities)
The xamlx is the simple out of box one that it generates with GetData passing in an int and returns the int.ToString()
What am I missing?
Code Following:
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 * If I add the following in to the AssemblyReference array
,new AssemblyReference
{
Assembly = typeof (WorkflowService).Assembly
}
, it compiles fine... but still gives the me original error of
Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled
链接地址: http://www.djcxy.com/p/17174.html
上一篇: 在工作流程服务中添加服务参考地址