0

我正在为 SharePoint Foundation 2010 开发 asp.net mvc 应用程序。asp.net 应用程序托管在一台机器上,而 SharePoint Foundation 2010 托管在另一台机器上。我在 SharePoint 环境的 ISAPI 文件夹中部署了一项自定义 wcf 服务。此自定义 wcf 服务以编程方式创建内容数据库。asp.net 应用程序使用此自定义 wcf 服务。我正在使用这种方法,因为我的场景类似于链接 - http://blog.sharedove.com/adisjugo/index.php/2012/07/31/creating-site-collections-in-specific-content-database/ . 实现上述场景我遇到了错误 - http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/f10d009b-13c4-4942-86b4-2ab8c4f5994d。我已经解决了这个错误http://beyondweblogs.com/sharepoint-2010-sppersistedobject-access-denied/。现在我收到错误 - System.InvalidOperationException:由于对象的当前状态,操作无效。

System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext context)
   at Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest()
   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
   at Microsoft.SharePoint.Administration.SPPersistedChildCollection`1.Add(T newObj, Boolean ensure)
   at Microsoft.SharePoint.Administration.SPPersistedChildCollection`1.Ensure(T newObj)
   at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(Guid newDatabaseId, String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status, Boolean provision, Guid lockId, Int32 addFlags)
   at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status)
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.<createContentDb>b__7()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.createContentDb()
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.<>c__DisplayClass3.<GetName>b__1()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.GetName()

上面的链接bolg.sharedove.com 中描述了此错误。我想我需要按照 bolg.sharedove.com 中的描述设置以下代码

var storeContext = HttpContext.Current; 
HttpContext.Current = null; 
// do your code 
HttpContext.Current = storeContext;

我认为我无法在 wcf 服务中设置上述代码。我试图在 asp.net 应用程序中设置它,但发生了同样的错误。anuone可以告诉我应该在哪里设置这个代码?如果有人有不同的解决方案,请分享。

4

1 回答 1

0

我只是在 wcf 服务应用程序中添加了对 System.Web.dll 的引用。现在我可以在 wcf 中使用 HttpContext。我在 wcf 中设置了以下代码

var storeContext = HttpContext.Current; 
HttpContext.Current = null; 
// do your code 
HttpContext.Current = storeContext;

现在 wcf 中的所有代码都可以正常工作。我现在能够以编程方式创建内容数据库和网站集。

于 2013-05-08T03:17:50.670 回答