2011-11-07 102 views
0

我試圖實現授權作爲Seroter描述here(服務授權部分)。我已經GAC了圖書館,更改了machine.config並能夠在選擇行爲擴展對話框中選擇自定義行爲。但我不能設置'WindowsGroup'的值,它給了我「對象引用沒有設置爲對象的實例」,我不明白爲什麼。有沒有人實施服務授權?BizTalk服務授權

回答

1

終於解決了這個問題。

using System; 
using System.Configuration; 
using System.ServiceModel.Configuration; 

namespace Esb.Service.Authorization 
{ 
    public class EsbBehaviorElement : BehaviorExtensionElement 
    { 
     private const string _windowsgroupIndexName = "windowsgroup"; 

     public EsbBehaviorElement() 
     { 
      if (!base.Properties.Contains(_windowsgroupIndexName)) 
      { 
       base.Properties.Add(new ConfigurationProperty(_windowsgroupIndexName, typeof(string))); 
      } 
     } 

     [ConfigurationProperty("WindowsGroup", IsRequired = false, DefaultValue = "")] 
     public string WindowsGroup 
     { 
      get 
      { 
       return (string)base[_windowsgroupIndexName]; 
      } 
      set 
      { 
       base[_windowsgroupIndexName] = value; 
      } 
     } 

     public override Type BehaviorType 
     { 
      get 
      { 
       return typeof(EsbServiceBehavior); 
      } 
     } 

     protected override object CreateBehavior() 
     { 
      return new EsbServiceBehavior(WindowsGroup); 
     } 
    } 
} 

我不知道爲什麼Seroter的解決方案作品,未經構造函數,其中一個應該「windowsgroup」屬性添加到屬性的基本集合。

+0

感謝您發佈解決方案! – StuartLC