Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SharePoint BDC模型和WCF_Wcf_Visual Studio 2010_Sharepoint 2010_Bdc - Fatal编程技术网

SharePoint BDC模型和WCF

SharePoint BDC模型和WCF,wcf,visual-studio-2010,sharepoint-2010,bdc,Wcf,Visual Studio 2010,Sharepoint 2010,Bdc,这是我的设想 我已经在VS2010中创建了一个BDC模型项目,以便在SharePoint2010中部署。我已经为我们在另一个系统上运行的WCF服务添加了一个服务引用。我希望我的ReadList方法调用另一个系统上的WCF服务,以提取要显示在列表中的数据 我已经为ReadList方法创建了一个单元测试,以在部署之前验证它是否有效。我得到的错误消息是“在ServiceModel客户端配置部分中找不到引用约定'TicketsWCF.ITickets'的默认端点元素。” 当我添加服务引用时,一个app.

这是我的设想

我已经在VS2010中创建了一个BDC模型项目,以便在SharePoint2010中部署。我已经为我们在另一个系统上运行的WCF服务添加了一个服务引用。我希望我的ReadList方法调用另一个系统上的WCF服务,以提取要显示在列表中的数据

我已经为ReadList方法创建了一个单元测试,以在部署之前验证它是否有效。我得到的错误消息是“在ServiceModel客户端配置部分中找不到引用约定'TicketsWCF.ITickets'的默认端点元素。”

当我添加服务引用时,一个app.config被添加到项目中,它似乎拥有运行服务所需的一切

我的两个问题是

  • 是否有人获得了使用BDC的非sharepoint外部系统的WCF服务

  • 部署模型时,app.config设置是否会正确放置在sharepoint系统中


  • 不幸的是,在这种情况下,我还没有找到使用应用程序配置文件的方法。一种解决方法是在代码中定义端点,并可能将端点地址保存在场属性包中。请注意,您必须添加对System.ServiceModel的引用

        private static string endpointUri = SPContext.Current.Site.WebApplication.Farm.Properties["Service_Uri_PropertyBag_Key"] as string;
        private static EndpointAddress endpoint = new EndpointAddress(endpointUri);
        private static BasicHttpBinding binding = new BasicHttpBinding();
    
    然后,调用WCF服务类似于:

            using (ReferencedServiceClient client = new ReferencedServiceClient(binding, endpoint))
            {
                return client.ReadList();
            }
    

    我曾在许多项目中使用WCF与BDC合作。我通常做的事情如下所述

    1) 创建一个名为SPCommon的单独SharePoint解决方案

    2) 添加服务引用

    3) 创建MyAppSettings.cs

     public class MyAppSettings
     {
        public string MyServiceEndPoint
        {
           get;
           set;
        }
     }
    
    4) 创建ConfigurationManager.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using System.Configuration;
    using System.Web.Configuration;
    using Microsoft.SharePoint.Administration;
    
    namespace MyApp
    {
       public class ConfigurationManager
        {       
           SPSite site;
    
           public ConfigurationManager(SPSite site)
           {
               this.site = site;        
           }
    
           public MyAppSettings GetAppSettings()
           {
               try
               {
                   System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/", site.WebApplication.Name);
                   AppSettingsSection appSettingSection = config.AppSettings;
    
                   MyAppSettings settings = new MyAppSettings();
                   settings.MyServiceEndPoint = appSettingSection.Settings["MyServiceEndPoint"].Value;
    
                   return settings;
               }
               catch (Exception ex)
               {
                   // Log Error              
               }
               return null;
           }
        }
    }
    
    5) 创建MyServiceConnection.cs文件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using MyServiceReference;
    using System.ServiceModel;
    using Microsoft.SharePoint;
    
    namespace MyApp
    {
        public class MyServiceConnection
        {
            public const int _maxBufferSize = 2147483647;
            public const int _maxReceivedBufferSize = 2147483647;
            public const int _maxStringContentLength = 2147483647;
            public const int _maxArrayLength = 2147483647;
            public const int _maxBytesPerRead = 2147483647;
            public const int _maxNameTableCharCount = 2147483647;
            public const int _maxDepth = 2147483647;   
    
            public static MyServiceProxyClient GetMyServiceProxyClient()
            {
                SPSite site = SPContext.Current.Site;
    
                // Get the EndPointUrl from Web.config appsetting
                ConfigurationManager configMgr = new ConfigurationManager(site);
                var appSetting = configMgr.GetAppSettings();
    
                EndpointAddress myServicecrmEndPoint;
    
                if (appSetting != null)
                {
                    myServiceEndPoint = new EndpointAddress(appSetting.MyServiceEndPoint);
    
                    var proxy = new MyServiceProxyClient(
                        new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly)
                        {
                            MaxBufferSize = _maxBufferSize,
                            MaxReceivedMessageSize = _maxReceivedBufferSize,
                            ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                            {
                                MaxStringContentLength = _maxStringContentLength,
                                MaxArrayLength = _maxArrayLength,
                                MaxBytesPerRead = _maxBytesPerRead,
                                MaxNameTableCharCount = _maxNameTableCharCount,
                                MaxDepth = _maxDepth
                            },
                        },
                        myServiceEndPoint
                    );
                    return proxy;
                }
                else
                {
                    // Log Error
    
                    return null;
                }            
            }      
        }
    }
    
    6) 在外部列表解决方案中,添加对SPCommon项目的引用

    7) 调用服务方法ReadMyList(),如下所示

    8) 将appsetting添加到Web.config

      <appSettings>
        <add key="MyServiceEndPoint" value="http://localhost:8101/MyService.svc" />
      </appSettings>
    
    
    

    9) 确保同时部署SPCommon和External List解决方案。

    如果您在VS2010中创建BDC模型项目,则可能使用的是BDC.NET程序集连接器。您能否确认这是您的设置BDC->.NET程序集连接器->WCF->外部系统?我的设置是BDC->WCF->External System。如果要创建使用WCF的BDC,请使用SharePoint Designer开始。这里有一个例子
      <appSettings>
        <add key="MyServiceEndPoint" value="http://localhost:8101/MyService.svc" />
      </appSettings>