Problem with pluggable workflows, getting null
-
16-10-2019 - |
Question
I have this code in the call external method.
private void callExternalMethodActivity1_MethodInvoking(object sender, EventArgs e)
{
callExternalMethodActivitysitename = twInfo.Code;
callExternalMethodActivityurl = workflowProperties.WebUrl;
}
AND the method in the pluggable workflow service has:
public void CreateTrainingSite(string sitename, string url) { //CODE HERE }
When I step into the first method the properties are filled, however when I step into the second method the variables are null.
Please help
Edited:
namespace TrainingApprovalSiteWorkflow {
[ExternalDataExchange]
public interface ITrainingSiteCreationService
{
event EventHandler<CommunicationObjArgs> MessageIn;
void CreateTrainingSite(string sitename, string url);
}
[Serializable]
public class CommunicationObjArgs : ExternalDataEventArgs
{
public CommunicationObjArgs(Guid id) : base(id) { }
public string webID;
}
class StateObject
{
public SPWeb web;
public Guid instanceId;
public StateObject(Guid instanceId, SPWeb web)
{
this.instanceId = instanceId;
this.web = web;
}
}
class TrainingSiteCreationService : SPWorkflowExternalDataExchangeService, ITrainingSiteCreationService
{
public event EventHandler<CommunicationObjArgs> MessageIn;
public void CreateTrainingSite(string sitename, string url)
{
ThreadPool.QueueUserWorkItem(delegate(object state)
{
StateObject sObject = state as StateObject;
string webID = string.Empty;
using (SPSite siteCollection = new SPSite(url))
{
using (SPWeb web = siteCollection.OpenWeb())
{
using (SPWeb trainingWeb = web.Webs.Add(sitename))
{
trainingWeb.Description = "This site is created by a pluggable workflow service.";
trainingWeb.Title = sitename;
trainingWeb.Update();
webID = trainingWeb.ID.ToString();
}
}
}
RaiseEvent(sObject.web, sObject.instanceId,
typeof(ITrainingSiteCreationService),
"MessageIn", new object[] { webID });
}, new StateObject(WorkflowEnvironment.WorkflowInstanceId,
this.CurrentWorkflow.ParentWeb));
}
public override void CallEventHandler(Type eventType, string eventName, object[] eventData, SPWorkflow workflow, string identity, IPendingWork workHandler, object workItem)
{
var msg = new CommunicationObjArgs(workflow.InstanceId);
msg.webID = eventData[0].ToString();
msg.WorkHandler = workHandler;
msg.WorkItem = workItem;
msg.Identity = identity;
this.MessageIn(null, msg);
}
public override void CreateSubscription(MessageEventSubscription subscription)
{
throw new NotImplementedException();
}
public override void DeleteSubscription(Guid subscriptionId)
{
throw new NotImplementedException();
}
}
}
Solution 2
I was able to find the problem.
On the onworkflow activated Invoking method I was setting another fields,
and no these
callExternalMethodActivitysitename = twInfo.Code;
callExternalMethodActivityurl = workflowProperties.WebUrl;
so, when it gets to the call external method, they were blank, too obvius after looking it very detailed.
OTHER TIPS
I would suggest you to create a custom business object which has these two properties. Further you need to make this object serializable and use this object to communicate with the method in your workflow service.
I did something like this yestarday and it works like a charm when you need to supply multiple parameters to your WF service.