首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SharePoint BDC模型与WCF

SharePoint BDC模型与WCF
EN

Stack Overflow用户
提问于 2011-06-06 23:15:53
回答 2查看 1.3K关注 0票数 1

这是我的场景..。

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

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

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

我的两个问题是

  1. 有任何人在使用BDC
  2. 的非sharepoint外部系统中获得WCF服务,当模型被部署时,app.config设置会被适当地放置在sharepoint系统?

中吗?

EN

回答 2

Stack Overflow用户

发布于 2013-10-05 14:41:41

不幸的是,在本例中,我还没有找到使用app配置文件的方法。一种方法是在代码中定义端点,并可能将端点地址保存在农场属性包中。请注意,您必须添加对System.ServiceModel的引用。

代码语言:javascript
复制
    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服务将类似于:

代码语言:javascript
复制
        using (ReferencedServiceClient client = new ReferencedServiceClient(binding, endpoint))
        {
            return client.ReadList();
        }
票数 0
EN

Stack Overflow用户

发布于 2013-10-09 23:58:20

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

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

2)添加服务参考

3)创建MyAppSettings.cs

代码语言:javascript
复制
 public class MyAppSettings
 {
    public string MyServiceEndPoint
    {
       get;
       set;
    }
 }

4)创建ConfigurationManager.cs

代码语言:javascript
复制
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文件

代码语言:javascript
复制
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(),如下所示

代码语言:javascript
复制
MyServiceProxyClient service = SPCommon.GetMyServiceProxyClient();
listData = service.ReadMyList();

8)将追加添加到Web.config中

代码语言:javascript
复制
  <appSettings>
    <add key="MyServiceEndPoint" value="http://localhost:8101/MyService.svc" />
  </appSettings>

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6259078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档