博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将一个webservice项目add到 sharepoint webapplication中,通过外部程序调用这个webservice进行简要的sharepoint常规操作。

 

在Site collection future中启用workflow. 使用sharepoint 自带的两个workflow.

1.feedback workflow

2. Approver - Sharepoint 2010 workflow

代码片段: 

 

var replaceSpace = new Regex(@"\s{1,}", RegexOptions.IgnoreCase);

                   
                    var list = common.GetList(rootweb, listName);//rootweb.Lists.TryGetList(listName);
                    if (null == list)
                    {
                        workflowResultEnum =  WorkflowResultEnum.HaveNotWorkflow;
                        return;
                    }

                    var currentUserName = replaceSpace.Replace(userprofile.DisplayName, ".");
                    currentUserName = currentUserName + "_Approver-Sharepoint2010";

                    var currentUserWorkflowAssociation = list.WorkflowAssociations.GetAssociationByName(currentUserName,
                                                                                                        System.Globalization
                                                                                                            .CultureInfo.
                                                                                                            CurrentCulture);
                    if (null == currentUserWorkflowAssociation)
                    {
                        var rootWebWorkflowTemplateCollection = rootweb.WorkflowTemplates;
                        var approverTemplate = rootWebWorkflowTemplateCollection.GetTemplateByName(approverWorkflowName,
                                                                            System.Globalization.CultureInfo.CurrentCulture);
                        if (null == approverTemplate)
                        {
                            workflowResultEnum = WorkflowResultEnum.HaveNotWorkflow;
                            return;
                           
                        }
                        currentUserWorkflowAssociation = SPWorkflowAssociation.CreateListAssociation(approverTemplate,
                                                                                                     currentUserName,
                                                                                                     tasksList,
                                                                                                     workflowHistory);
                        list.WorkflowAssociations.Add(currentUserWorkflowAssociation);
                        currentUserWorkflowAssociation.Enabled = true;
                        list.Update();
                    }
                    var buildApproverWorkflowXml = new BuildApproverWorkflowXml(currentUserWorkflowAssociation.AssociationData);
                    var personaSharepoints = new List<PersonaSharepoint>();
                    foreach (var spUserId in selectUsers)
                    {
                        var spUser = rootSiteUsers.GetByID(spUserId);
                        if (null == spUser) continue;
                        var personaSharepoint = new PersonaSharepoint
                        {
                            DisplayName = spUser.Name,
                            AccountId = spUser.LoginName,
                            AccountType = "User"
                        };
                        personaSharepoints.Add(personaSharepoint);
                    }
                    currentUserWorkflowAssociation.AssociationData = buildApproverWorkflowXml.Build(personaSharepoints, requestText, customerDateTime);
                    

                    var item = list.GetItemByUniqueId(itemUniqueId);
                    if (null == item)
                    {
                        workflowResultEnum = WorkflowResultEnum.HaveNotWorkflow;
                        return;
                    }

                    item.Web.Site.WorkflowManager.StartWorkflow(item, currentUserWorkflowAssociation,
                                                         currentUserWorkflowAssociation.AssociationData,true);

                    rootweb.AllowUnsafeUpdates = false;


 其中SP代码做的操作是获取workflowAssociation,未找到便根据相应模版创建workflowAssociation.以及创建和检查task List和workflowhistory List;

该workflow的associationdata的XML格式为:

 View Code 

 
<dfs:myFields xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dfs:queryFields></dfs:queryFields>
  <dfs:dataFields>
    <d:SharePointListItem_RW>
      <d:Approvers>
        <d:Assignment>
          <d:Assignee />
          <d:Stage xsi:nil="true" />
          <d:AssignmentType>Serial</d:AssignmentType>
        </d:Assignment>
      </d:Approvers>
      <d:ExpandGroups>true</d:ExpandGroups>
      <d:NotificationMessage />
      <d:DueDateforAllTasks xsi:nil="true" />
      <d:DurationforSerialTasks xsi:nil="true" />
      <d:DurationUnits>Day</d:DurationUnits>
      <d:CC />
      <d:CancelonRejection>false</d:CancelonRejection>
      <d:CancelonChange>false</d:CancelonChange>
      <d:EnableContentApproval>false</d:EnableContentApproval>
    </d:SharePointListItem_RW>
  </dfs:dataFields>

 

将该workflow绑定在一个listitem中,并启动。启动方式为自动启动,当调用webservice后未发现异常信息,但是在sharepoint界面发现启动失败。

 

查看LOGS日志后发现该日志信息:


06/07/2012 15:37:27.62 w3wp.exe (0x23CC)                       0x2860 SharePoint Foundation         Workflow Infrastructure       72fs Unexpected RunWorkflow: Microsoft.SharePoint.SPException: <Error><CompilerError Line="0" Column="0" Text="Application configuration file is either missing or does not contain authorizedTypes related configuration information." /></Error>     at Microsoft.SharePoint.Workflow.SPNoCodeXomlCompiler.LoadXomlAssembly(SPWorkflowAssociation association, SPWeb web)     at Microsoft.SharePoint.Workflow.SPWinOeHostServices.LoadDeclarativeAssembly(SPWorkflowAssociation association)     at Microsoft.SharePoint.Workflow.SPWinOeHostServices.CreateInstance(SPWorkflow workflow)     at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)     at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow workflow, ...  
06/07/2012 15:37:27.62* w3wp.exe (0x23CC)                       0x2860 SharePoint Foundation         Workflow Infrastructure       72fs Unexpected ...Collection`1 events, SPWorkflowRunOptionsInternal runOptions)

 搜索之后发现在微软网站有如下解释:

http://office.microsoft.com/en-us/sharepoint-designer-help/troubleshoot-workflow-errors-HA010237912.aspx#BM39 

大致意思是有问题的话是System account替你Cancelled的。接下来,无论我提高任何权限都无法调用自己的webservice启动workflow.

后来在这个帖子下发现有回复说需要在config文件中增加sectiongroup节点;

http://social.msdn.microsoft.com/Forums/zh-CN/biztalkr2adapters/thread/c017ed05-6acc-4c22-bcd1-f196698f91e4