1
votes

I have a custom built web service that is built to simply add items into a list in SharePoint Foundation 2010. I have workflow attached to the list but when I create an item using my web service (which references the SharePoint Object Model) workflows 'Fail on Start'. If I add an item to the list directly within SharePoint the workflows start as required with no problems. I have tried the following so far (including all variations of using them together) but non of these fix the issue:

  • Using SPSecurity.RunWithElevatedPrivilages to run my code
  • Impersonating a different user to the Administrator and System Account to create the item as
  • Running my application pool as the same user as my site's application pool
  • Running my application pool as a different account to my site's application pool user The web service is not failing and it is creating the items, just the workflows are not running... can anyone help me with this please?

The code I am using to create the list item is as follows:

 SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            SPSite oTempSite = new SPSite(SharePointSite);
            SPUser oUserImpersonate = oTempSite.OpenWeb().EnsureUser(UserToEntryAs);

            SPSite oSite = new SPSite(SharePointSite, oUserImpersonate.UserToken);
            SPWeb oWeb = oSite.OpenWeb();

            try
            {
                oSite.AllowUnsafeUpdates = true;
                oWeb.AllowUnsafeUpdates = true;

                SPList oList = oWeb.Lists["Sample Log"];

                SPListItem oNewItem = oList.Items.Add();

                oNewItem["Customer"] = intCustomerID;
                oNewItem["Cust. Contact Name"] = strCustomerContactName;
                oNewItem["Contact Email"] = strCustomerContactEmail;
                oNewItem["Sample Number"] = strSampleNumber;
                oNewItem["Notes"] = strNotes;
                oNewItem["Application"] = strSampleApplication;
                oNewItem["Despatch Method"] = strDespatchMethod;
                oNewItem["Cost"] = dblCost;
                oNewItem["Sample 1"] = intSampleProductID;
                oNewItem["Weight 1"] = strSampleWeight;
                oNewItem["Batch No. 1"] = strSampleBatch;

                //Handle Account Manager(s):
                SPFieldUserValueCollection usrAccountManagers = new SPFieldUserValueCollection();
                foreach (string strAcctMrg in AccountManagers.Split(';'))
                {
                    SPUser oUser = oWeb.EnsureUser(strAcctMrg);
                    usrAccountManagers.Add(new SPFieldUserValue(oWeb, oUser.ID, oUser.LoginName));
                }
                oNewItem["Account Manager"] = usrAccountManagers;

                oNewItem["Content Type"] = "Ingredient Sample"; //Set the content type to be 'Ingredient Sample'
                oNewItem["Ingredient Sample Status"] = "Awaiting Result"; //Set the status to default to 'Awaiting Result'

                oNewItem.Update();

Thanks in advance...

1
Please add the source code from the service that adds an item and add the error message of the workflow.Maks Matsveyeu
@MaksMatsveyeu - I have added the source code, apologies for missing this off and thanks in advance for your helpLuke

1 Answers

2
votes

After researching the ULS log errors I found the issue was with my web.config file on my Web Service that needed the Authorized types declaring for the workflows to be able to run on the item I had created.

I used this post to help me resolve it: http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/71d23c0e-24c5-4d61-8d62-265c374ac81c/