您的自定义操作应调用javascript function
或执行GET request
您的 SharePoint 托管WCF
或ASMX
WebService。
官方 MSDN Walktrought:创建自定义 ASP.NET Web 服务
有关具有更多屏幕截图的其他资源,请查看此博客文章:演练:在 SharePoint 2010 中创建自定义 ASP.NET (ASMX) Web 服务
官方 Technet 演练:SharePoint 2013:创建在 SharePoint 中托管并在 WSP 中部署的自定义 WCF REST 服务
注意:GET request
你需要web.AllowUnsafeUpdate = true
使用 javascript 你需要AJAX
调用jQuery.ajax()
/编辑
要连接 Web 服务和您的自定义操作,请使用 SharePoint Desinger,删除或更改您现有的自定义操作,将类型更改为Navigate to URL
和文本框类型:
javascript: (function() { console.log('Testing...' + {ItemId}); /* your web service call */ })();
使用{ItemId}
别名将正确的项目 ID 传递给您的 AJAX 调用。
另一方面,在 Web 服务端使用SPWorkflowManager
类来启动项目的工作流。检查下面的代码(链接):
public void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName) {
SPList parentList = listItem.ParentList;
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
foreach (SPWorkflowAssociation association in associationCollection) {
if (association.Name == wfName){
association.AutoStartChange = true;
association.AutoStartCreate = false;
association.AssociationData = string.Empty;
spSite.WorkflowManager.StartWorkflow(listItem, association, association.AssociationData);
}
}
}