2011-06-06 60 views
1

這是我的場景..SharePoint BDC模型和WCF

我在VS2010中創建了一個BDC模型項目,用於在SharePoint2010中進行部署。我已經將服務引用添加到我們在另一個系統上運行的WCF服務。我想讓我的ReadList方法調用另一個系統上的WCF服務,以便將數據顯示在列表中。

我已經爲ReadList方法創建了一個單元測試,以驗證它在部署之前是否有效。我得到的錯誤消息是「在ServiceModel客戶端配置部分找不到引用合同'TicketsWCF.ITickets'的默認端點元素。」

當我添加服務引用時,將一個app.config添加到項目中,該項目似乎具有運行服務所需的所有內容。

我的兩個問題是

  1. 有沒有人得到了一個WCF服務到非SharePoint外部系統,BDC

  2. 當模型部署將在app.config設置得到適當設置工作在分享點系統內?

+0

如果您在VS2010中創建BDC模型項目,則可能使用的是BDC .NET Assembly Connector。你能確認這是你的設置BDC - > .NET Assembly Connector - > WCF - > External System嗎?我有它的工作,但我的設置是BDC - > WCF - >外部系統。 – MLF 2011-06-07 15:25:09

+1

如果要創建使用WCF的BDC,請使用SharePoint Designer讓您開始。以下是一個示例[使用WCF和SharePoint Designer 2010的Business Connectivity Services(BCS)](http://malikhan.wordpress.com/2010/01/11/business-connectivity-services-bcs-using-wcf-sharepoint-designer -2010 /) – MLF 2011-06-07 17:22:10

回答

0

不幸的是,在這種情況下,我還沒有找到使用應用程序配置文件的方法。解決方法之一是在代碼中定義端點,並可能將端點地址保存在服務器場屬性包中。請注意,您將不得不添加一個對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(); 
     } 
0

我已經使用WCF在很多項目中與BDC工作。我通常做的事情在下面描述。

1)創建名爲SPCommon

2的單獨的SharePoint溶液)添加服務引用

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)在外部列表的解決方案,如下面

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

8)添加到appsetting web.config中SPCommon項目

7)調用服務方法ReadMyList()添加參考

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

9)確保同時部署SPCommon和External List解決方案。