1

我想寻求帮助。我需要编写远程连接到 Sharepoint 服务(BDC 服务)并在 BDC 元数据存储中进行任何更新的代码。在 msdn 中,我找到了这个示例:

using (SPSite site = new SPSite("http://ssdk-server/Pages/Default.aspx"))
{
    using (new Microsoft.SharePoint.SPServiceContextScope(SPServiceContext.GetContext(site)))
    {
         BdcService service = SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
         IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);

         IEntity entity = catalog.GetEntity("http://ssdk-server/sdksamples", "Customer");
         ILobSystemInstance LobSysteminstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;


         IView createView = entity.GetCreatorView("Create");
         IFieldValueDictionary valueDictionary = createView.GetDefaultValues();
         valueDictionary["Name"] = "some name";
         Identity id = entity.Create(valueDictionary, LobSysteminstance);
     }
 }

但是,这在第一行抛出异常:

FileNotFoundException (The Web application at http://sharepoint/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.). 

我发现了同样的麻烦,但提出的解决方案(将项目设置框架更改为 3.5,将平台更改为 x64)对我没有帮助。

谁能告诉我,是否可以远程连接到 BDC 服务并将任何数据加载到元数据存储中,如果可以,我该怎么做。

4

1 回答 1

1

无法以这种方式连接到远程共享点服务器。您应该使用客户端上下文

例如:

    string siteUrl = "http://MyServer/sites/MySiteCollection";

    ClientContext clientContext = new ClientContext(siteUrl);
    Web oWebsite = clientContext.Web;
    ListCollection collList = oWebsite.Lists;

    clientContext.Load(collList);

    clientContext.ExecuteQuery();

    foreach (SP.List oList in collList)
    {
        Console.WriteLine("Title: {0} Created: {1}", oList.Title, oList.Created.ToString());
    }

你可以在这里找到更多的例子

于 2012-10-08T09:04:30.463 回答