SharePoint BDC 模型和 WCF

发布于 2024-11-14 07:42:46 字数 454 浏览 7 评论 0原文

这是我的场景..

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

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

当我添加服务引用时,app.config 会添加到项目中,该项目似乎包含运行服务所需的一切。

我的两个问题是

  1. 是否有人获得了与 BDC 合作的非共享点外部系统的 WCF 服务

  2. 当模型为部署后,app.config 设置是否会正确放置在 sharepoint 系统中?

Here is my scenario..

I have created a BDC model project in VS2010 for deployment in SharePoint2010. I have added a service reference to a WCF service that we have running on another system. I want my ReadList method to call the WCF service on the other system to pull data to be shown in the list.

I have created a unit test for the ReadList method to verify it works before deploying. The error message that I get is "Could not find default endpoint element that references contract 'TicketsWCF.ITickets' in the ServiceModel client configuration section."

When I add the service reference an app.config is added to the project which appears to have everything that I need for the service to run.

My two questions are

  1. Has anyone gotten a WCF service to a non-sharepoint external system working with BDC

  2. When the model is deployed will the app.config settings get appropriately placed within the sharepoint system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终难愈 2024-11-21 07:42:46

不幸的是,我还没有找到在这种情况下使用应用程序配置文件的方法。解决这个问题的一种方法是在代码中定义端点,并可能将端点地址保存在场属性包中。请注意,您必须添加对 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();
        }

Unfortunately, I haven't found a way to use an app config file in this case. One way around that is to define your endpoint in code, and possibly save the endpoint address in the farm property bag. Note that you will have to add a Reference to 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();

Then, making calls to your WCF service would be something similar to:

        using (ReferencedServiceClient client = new ReferencedServiceClient(binding, endpoint))
        {
            return client.ReadList();
        }
通知家属抬走 2024-11-21 07:42:46

我在许多项目中使用了 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() 如下

MyServiceProxyClient service = SPCommon.GetMyServiceProxyClient();
listData = service.ReadMyList();

8) 将 appsetting 添加到 Web.config

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

9) 确保部署 SPCommon 和外部列表解决方案。

I have used WCF working with BDC in many projects. What I usually do is described below.

1) Create a separate SharePoint solution called SPCommon

2) Add Service Reference

3) Create MyAppSettings.cs

 public class MyAppSettings
 {
    public string MyServiceEndPoint
    {
       get;
       set;
    }
 }

4) Create 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) Create a MyServiceConnection.cs file

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) In the external list solution, add reference to SPCommon project

7) Call the service method ReadMyList() as below

MyServiceProxyClient service = SPCommon.GetMyServiceProxyClient();
listData = service.ReadMyList();

8) Add appsetting to Web.config

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

9) Make sure to deploy both SPCommon and External List solutions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文