C#WCF System.Configuration.ConfigurationErrorsException:无法识别的元素'ManagedService' [英] C# WCF System.Configuration.ConfigurationErrorsException: Unrecognized element 'ManagedService'

查看:2107
本文介绍了C#WCF System.Configuration.ConfigurationErrorsException:无法识别的元素'ManagedService'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WCF应用程序中,我有一些自定义配置类,用于 app.config 。但是,我从WCF服务主机(它尝试检索WCF服务的构造函数中的自定义配置)中获取以下堆栈跟踪:


System.Reflection.TargetInvocationException:调用的目标抛出了
异常。 --->
System.Configuration.ConfigurationErrorsException:无法识别的
元素'ManagedService'。 (Service.dll.config line 8)
System.Configuration.BaseConfigurationRecord.EvaluateOne(String []
keys,SectionInput input,Boolean isTrusted,FactoryRecord
factoryRecord,SectionRecord sectionRecord,Object parentResult)
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord
factoryRecord,SectionRecord sectionRecord,Object parentResult,
Boolean getLkg,Boolean getRuntimeObject,Object& result,Object&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object& result,Object&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object& result,Object&
resultRuntimeObject)at
系统.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object&结果,对象&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSection(String
configKey)at
System.Configuration.ConfigurationManager.GetSection(String
sectionName)at ManagementService .. ctor()in
ManagementService.cs:line 42 ---内部异常堆栈跟踪结束
---在System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo
方法,Object [] args,SignatureStruct& ; signature,RuntimeType
declaringType)at
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
invokeAttr,Binder binder,Object [] parameters,CultureInfo文化)

at
System.ServiceModel.Description.ServiceDescription.CreateImplementation(Type
serviceType)at
System.ServiceModel.Description.ServiceDescription.GetService(Type
serviceType)at
System.ServiceModel .ServiceHost.CreateDescription(IDictionary`2&
implementsContracts)在
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection
baseAddresses)在System.ServiceModel.ServiceHost..ctor(类型
serviceType,Uri [] baseAddresses)at
Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(类型类型,
ServiceKind种类)在
Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo
info)System.Configuration.ConfigurationErrorsException:无法识别的
元素'ManagedService'。 (Service.dll.config line 8)
System.Configuration.BaseConfigurationRecord.EvaluateOne(String []
keys,SectionInput input,Boolean isTrusted,FactoryRecord
factoryRecord,SectionRecord sectionRecord,Object parentResult)
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord
factoryRecord,SectionRecord sectionRecord,Object parentResult,
Boolean getLkg,Boolean getRuntimeObject,Object& result,Object&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object& result,Object&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object& result,Object&
resultRuntimeObject)at
系统.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey,Boolean getLkg,Boolean checkPermission,Boolean
getRuntimeObject,Boolean requestIsHere,Object&结果,对象&
resultRuntimeObject)at
System.Configuration.BaseConfigurationRecord.GetSection(String
configKey)at
System.Configuration.ConfigurationManager.GetSection(String
sectionName)at ManagementService .. ctor()in
ManagementService.cs:line 42


(对于讨厌的堆栈跟踪)

我在这里看过很多关于这个错误的教程和其他问题,没有任何建议或解决方案到达任何地方。



以下是 app.config

的相关部分:

  configSections> 
< section name =ManagedServicestype =Service.Configuration.ManagedServicesSection,Service,Version = 1.0.0.0,Culture = neutralallowLocation =trueallowDefinition =EverywhererestartOnExternalChanges =false/> ;
< / configSections>
< ManagedServices>
< services>
< ManagedService serviceAssembly =ServiceserviceType =Service.Runnables.HostManagerRunneridentifier =HostManagerpriority =0>
< clear />
< / ManagedService>
< ManagedService serviceAssembly =ServiceserviceType =Service.Runnables.TimeoutMonitoridentifier =TimeoutMonitorpriority =0>
< add key =timeoutLengthvalue =30/>
< add key =runIntervalvalue =30/>
< / ManagedService>
< / services>
< / ManagedServices>

基本上,这个WCF服务用于管理其他服务,动态加载和启动 c> ManagedServicesSection

code>

  public class ManagedServicesSection: ConfigurationSection 
{

[ConfigurationProperty(services,IsDefaultCollection = true)]
public ManagedServiceCollection ServiceCollection
{
get {return(ManagedServiceCollection)base [ 服务]; }
}

}

< services> 是继承自 ConfigurationElementCollection MangedServiceCollection >

  public class ManagedServiceCollection:ConfigurationElementCollection 
{

public ManagedServiceCollection b {
}

public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}

public ManagedService this [int index]
{
get {return BaseGet(index)as ManagedService; }
set
{
if(BaseGet(index)!= null)
BaseRemoveAt(index);

BaseAdd(index,value);
}
}

public ManagedService this [string name]
{
get {return BaseGet(name)as ManagedService; }
set
{
if(BaseGet(name)!= null)
BaseRemove(name);

BaseAdd(value);
}
}

protected override ConfigurationElement CreateNewElement()
{
return new ManagedService();
}

保护覆盖对象GetElementKey(ConfigurationElement元素)
{
return((ManagedService)element).Identifier;
}
}

此集合包含 ManagedService s继承自 ConfigurationElement

  class ManagedService:ConfigurationElement 
{
[ConfigurationProperty(serviceAssembly,IsRequired = true)]
public string ServiceAssembly
{
get {return(string)this [ serviceAssembly]; }
set {this [serviceAssembly] = value; }
}

[ConfigurationProperty(serviceType,DefaultValue =IRunnable,IsRequired = true)]
public string ServiceType
{
get { return(string)this [serviceType]; }
set {this [serviceType] = value; }
}

[ConfigurationProperty(identifier,IsRequired = true,IsKey = true)]
public string标识符
{
get {return string)this [identifier]; }
set {this [identifier] = value; }
}


[ConfigurationProperty(priority,DefaultValue = 0,IsRequired = false)]
public int优先级
{
get {return(int)this [priority]; }
set {this [priority] = value; }
}

[ConfigurationProperty(serviceParameters,IsDefaultCollection = true)]
public ServiceParameterCollection ServiceParameters
{
get {return(ServiceParameterCollection)base [ serviceParamters]; }
}
}

代码可能更容易看pastie pastie.org/private/jkiylqsrklpcdbtfdrajq

解决方案

我无法编译你的示例,ServiceParameterCollection缺少...所以我已经准备好了我的工作单位。这里我们去...



首先让我们创建配置类,注意AddItemName ConfigurationCollection参数(我认为这是你在代码中缺少的):

 使用System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

命名空间GP.Solutions.WF.DocumentProvider.Entities.SharePoint
{
///< summary>
///基本SharePoint 2010提供程序连接
///< / summary>
[Serializable]
public class SharePoint2010Settings:ConfigurationSection
{
///< summary>
/// DocumentStorageRoot
///< / summary>
[ConfigurationProperty(SiteUrl,IsRequired = true,DefaultValue =)]
public string SiteUrl
{
get {return(string)base [SiteUrl]; }
set {base [SiteUrl] = value; }
}

///< summary>
/// TitleProperty
///< / summary>
[ConfigurationProperty(TitleProperty,IsRequired = true,DefaultValue =Title)]
public string TitleProperty
{
get {return(string)base [TitleProperty] ; }
set {base [TitleProperty] = value; }
}

///< summary>
/// ProvideFileAsLink
///< / summary>
[ConfigurationProperty(ProvideFileAsLink,IsRequired = true,DefaultValue = true)]
public bool ProvideFileAsLink
{
get {return(bool)base [ProvideFileAsLink]; }
set {base [ProvideFileAsLink] = value; }
}

///< summary>
/// DocumentCategories
///< / summary>
[ConfigurationProperty(DocumentCategories)]
public SharePointDocumentCategoryCollection DocumentCategories
{
get {return(SharePointDocumentCategoryCollection)base [DocumentCategories]; }
set {base [DocumentCategories] = value; }
}

}

///< summary>
///保存SharePointDocumentCategory集合的配置元素
///< / summary>
[ConfigurationCollection(typeof(SharePointDocumentCategory),AddItemName =DocumentCategory,CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class SharePointDocumentCategoryCollection:ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement b $ b {
return new SharePointDocumentCategory();
}

保护的覆盖对象GetElementKey(ConfigurationElement元素)
{
return((SharePointDocumentCategory)element).CategoryName;
}
}

///< summary>
///保存特定文档类别信息的配置元素
///< / summary>
[Serializable]
public class SharePointDocumentCategory:ConfigurationElement
{
///< summary>
/// CategoryName
///< / summary>
[ConfigurationProperty(CategoryName,IsRequired = true,DefaultValue =)]
public string CategoryName
{
get {return(string)base [CategoryName]; }
set {base [CategoryName] = value; }
}

///< summary>
/// FolderName
///< / summary>
[ConfigurationProperty(FolderName,IsRequired = true,DefaultValue =)]
public string FolderName
{
get {return(string)base [FolderName]; }
set {base [FolderName] = value; }
}


///< summary>
/// TitleProperty
///< / summary>
[ConfigurationProperty(OverwriteFiles,IsRequired = true,DefaultValue = true)]
public bool OverwriteFiles
{
get {return(bool)base [OverwriteFiles]; }
set {base [OverwriteFiles] = value; }
}

///< summary>
/// DocumentCategories
///< / summary>
[ConfigurationProperty(CategoryFields)]
public SharePointCategoryFieldsCollection CategoryFields
{
get {return(SharePointCategoryFieldsCollection)base [CategoryFields]; }
set {base [CategoryFields] = value; }
}

}

///< summary>
///保存SharePointDocumentCategory集合的配置元素
///< / summary>
[ConfigurationCollection(typeof(SharePointDocumentCategory),AddItemName =CategoryField,CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class SharePointCategoryFieldsCollection:ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement b $ b {
return new SharePointCategoryField();
}

保护的覆盖对象GetElementKey(ConfigurationElement元素)
{
return((SharePointCategoryField)element).FieldName;
}
}

///< summary>
///确定特定字段的类
///< / summary>
[Serializable]
public class SharePointCategoryField:ConfigurationElement
{
///< summary>
/// FolderName
///< / summary>
[ConfigurationProperty(FieldName,IsRequired = true,DefaultValue =)]
public string FieldName
{
get {return(string)base [FieldName]; }
set {base [FieldName] = value; }
}
}

}

这里是web.config部分:

 < configSections> 
< sectionGroup name =CustomConfiguration>
< section name =SharePoint2010Sectiontype =GP.Solutions.WF.DocumentProvider.Entities.SharePoint.SharePoint2010Settings,CustomConfigurationallowDefinition =EverywhereallowLocation =true/>
< / sectionGroup>

< / configSections>

< CustomConfiguration>

< SharePoint2010Section SiteUrl =http:// serverTitleProperty =TitleProvideFileAsLink =false>
< DocumentCategories>

< DocumentCategory CategoryName =VhodniračuniFolderName =OverwriteFiles =true>
< CategoryFields>
< CategoryField FieldName =Datum/>
< CategoryField FieldName =Vrednost/>
< / CategoryFields>
< / DocumentCategory>

< DocumentCategory CategoryName =Zahtevek za dopustFolderName =OverwriteFiles =true>
< CategoryFields>
< CategoryField FieldName =Datum od/>
< CategoryField FieldName =Datum do/>
< / CategoryFields>
< / DocumentCategory>

< / DocumentCategories>
< / SharePoint2010Section>
< / CustomConfiguration>


In a WCF application I have some custom configuration classes for use in app.config. However, I'm getting the following Stack Trace from the WCF Service Host (It attempts to retrieve the custom configuration in the constructor of the WCF service):

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Configuration.ConfigurationErrorsException: Unrecognized element 'ManagedService'. (Service.dll.config line 8) at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at ManagementService..ctor() in ManagementService.cs:line 42 --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.ServiceModel.Description.ServiceDescription.CreateImplementation(Type serviceType) at System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind) at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info) System.Configuration.ConfigurationErrorsException: Unrecognized element 'ManagedService'. (Service.dll.config line 8) at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at ManagementService..ctor() in ManagementService.cs:line 42

(Sorry for the nasty stack trace).

I've looked at tons of tutorials and other questions here about this error and none of the suggestions or solutions have gone anywhere.

Here's the relevant portion of the app.config

<configSections>
     <section name="ManagedServices" type="Service.Configuration.ManagedServicesSection, Service, Version=1.0.0.0, Culture=neutral " allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="false" />
</configSections>
  <ManagedServices>
     <services>
        <ManagedService serviceAssembly="Service" serviceType="Service.Runnables.HostManagerRunner" identifier="HostManager" priority="0">
           <clear />
        </ManagedService>
        <ManagedService serviceAssembly="Service" serviceType="Service.Runnables.TimeoutMonitor" identifier="TimeoutMonitor" priority="0">
           <add key="timeoutLength" value="30" />
           <add key="runInterval" value="30" />
        </ManagedService>
     </services>
  </ManagedServices>

Basically, this WCF service is used to manage other services which are loaded and started dynamically (informed via this configuration) on start up.

<ManagedServices> is from the ManagedServicesSection which inherits from ConfigurationSection

public class ManagedServicesSection : ConfigurationSection
{

  [ConfigurationProperty("services", IsDefaultCollection = true)]
  public ManagedServiceCollection ServiceCollection
  {
     get { return (ManagedServiceCollection) base["services"]; }
  }

}

As you can see from this, <services> is a MangedServiceCollection which inherits from ConfigurationElementCollection

public class ManagedServiceCollection : ConfigurationElementCollection
{

  public ManagedServiceCollection()
  {
  }

  public override ConfigurationElementCollectionType CollectionType
  {
     get
     {
        return ConfigurationElementCollectionType.BasicMap;
     }
  }

  public ManagedService this[int index]
  {
     get { return BaseGet(index) as ManagedService; }
     set
     {
        if (BaseGet(index) != null)
           BaseRemoveAt(index);

        BaseAdd(index, value);
     }
  }

  public ManagedService this[string name]
  {
     get { return BaseGet(name) as ManagedService; }
     set 
     { 
        if (BaseGet(name) != null)
           BaseRemove(name);

        BaseAdd(value);
     }
  }

  protected override ConfigurationElement CreateNewElement()
  {
     return new ManagedService();
  }

  protected override object GetElementKey(ConfigurationElement element)
  {
     return ((ManagedService)element).Identifier;
  }
}

This collection holds ManagedServices which inherit from ConfigurationElement:

public class ManagedService : ConfigurationElement
{
  [ConfigurationProperty("serviceAssembly", IsRequired = true)]
  public string ServiceAssembly
  {
     get { return (string) this["serviceAssembly"]; }
     set { this["serviceAssembly"] = value; }
  }

  [ConfigurationProperty("serviceType", DefaultValue = "IRunnable", IsRequired = true)]
  public string ServiceType 
  { 
     get { return (string) this["serviceType"]; }
     set { this["serviceType"] = value; }
  }

  [ConfigurationProperty("identifier", IsRequired = true, IsKey = true)]
  public string Identifier
  {
     get { return (string) this["identifier"]; }
     set { this["identifier"] = value; }
  }


  [ConfigurationProperty("priority", DefaultValue = 0, IsRequired = false)]
  public int Priority
  {
     get { return (int) this["priority"]; }
     set { this["priority"] = value; }
  }

  [ConfigurationProperty("serviceParameters", IsDefaultCollection = true)]
  public ServiceParameterCollection ServiceParameters
  {
     get { return (ServiceParameterCollection)base["serviceParamters"]; }
  }
}

The code may be easier to look at in this pastie pastie.org/private/jkiylqsrklpcdbtfdrajq

解决方案

I could not complied your sample, ServiceParameterCollection was missing... so I have prepared you my working samle. Here we go...

First lets create config classes, take notice on AddItemName ConfigurationCollection parameter (I think this is what you are missing in your code):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace GP.Solutions.WF.DocumentProvider.Entities.SharePoint
{
    /// <summary>
    /// Base SharePoint 2010 provider contiguration
    /// </summary>
    [Serializable]
    public class SharePoint2010Settings : ConfigurationSection
    {
        /// <summary>
        /// DocumentStorageRoot
        /// </summary>
        [ConfigurationProperty("SiteUrl", IsRequired = true, DefaultValue = "")]
        public string SiteUrl
        {
            get { return (string)base["SiteUrl"]; }
            set { base["SiteUrl"] = value; }
        }

        /// <summary>
        /// TitleProperty
        /// </summary>
        [ConfigurationProperty("TitleProperty", IsRequired = true, DefaultValue = "Title")]
        public string TitleProperty
        {
            get { return (string)base["TitleProperty"]; }
            set { base["TitleProperty"] = value; }
        }

        /// <summary>
        /// ProvideFileAsLink
        /// </summary>
        [ConfigurationProperty("ProvideFileAsLink", IsRequired = true, DefaultValue = true)]
        public bool ProvideFileAsLink
        {
            get { return (bool)base["ProvideFileAsLink"]; }
            set { base["ProvideFileAsLink"] = value; }
        }

        /// <summary>
        /// DocumentCategories
        /// </summary>
        [ConfigurationProperty("DocumentCategories")]
        public SharePointDocumentCategoryCollection DocumentCategories
        {
            get { return (SharePointDocumentCategoryCollection)base["DocumentCategories"]; }
            set { base["DocumentCategories"] = value; }
        }

    }

    /// <summary>
    /// Configuration element that holds SharePointDocumentCategory collection
    /// </summary>
    [ConfigurationCollection(typeof(SharePointDocumentCategory), AddItemName = "DocumentCategory", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class SharePointDocumentCategoryCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new SharePointDocumentCategory();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SharePointDocumentCategory)element).CategoryName;
        }
    }

    /// <summary>
    /// Configuration element that holds information for specific document category
    /// </summary>
    [Serializable]
    public class SharePointDocumentCategory: ConfigurationElement
    {
        /// <summary>
        /// CategoryName
        /// </summary>
        [ConfigurationProperty("CategoryName", IsRequired = true, DefaultValue = "")]
        public string CategoryName
        {
            get { return (string)base["CategoryName"]; }
            set { base["CategoryName"] = value; }
        }

        /// <summary>
        /// FolderName
        /// </summary>
        [ConfigurationProperty("FolderName", IsRequired = true, DefaultValue = "")]
        public string FolderName
        {
            get { return (string)base["FolderName"]; }
            set { base["FolderName"] = value; }
        }


        /// <summary>
        /// TitleProperty
        /// </summary>
        [ConfigurationProperty("OverwriteFiles", IsRequired = true, DefaultValue = true)]
        public bool OverwriteFiles
        {
            get { return (bool)base["OverwriteFiles"]; }
            set { base["OverwriteFiles"] = value; }
        }

        /// <summary>
        /// DocumentCategories
        /// </summary>
        [ConfigurationProperty("CategoryFields")]
        public SharePointCategoryFieldsCollection CategoryFields
        {
            get { return (SharePointCategoryFieldsCollection)base["CategoryFields"]; }
            set { base["CategoryFields"] = value; }
        }

    }

    /// <summary>
    /// Configuration element that holds SharePointDocumentCategory collection
    /// </summary>
    [ConfigurationCollection(typeof(SharePointDocumentCategory), AddItemName = "CategoryField", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class SharePointCategoryFieldsCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new SharePointCategoryField();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SharePointCategoryField)element).FieldName;
        }
    }

    /// <summary>
    /// Class that determines specific field
    /// </summary>
    [Serializable]
    public class SharePointCategoryField : ConfigurationElement
    {
        /// <summary>
        /// FolderName
        /// </summary>
        [ConfigurationProperty("FieldName", IsRequired = true, DefaultValue = "")]
        public string FieldName
        {
            get { return (string)base["FieldName"]; }
            set { base["FieldName"] = value; }
        }
    }

}

And here is web.config part:

  <configSections>
    <sectionGroup name="CustomConfiguration">
      <section name="SharePoint2010Section" type="GP.Solutions.WF.DocumentProvider.Entities.SharePoint.SharePoint2010Settings,CustomConfiguration" allowDefinition="Everywhere" allowLocation="true"/>
    </sectionGroup>

  </configSections>

  <CustomConfiguration>

    <SharePoint2010Section SiteUrl="http://server" TitleProperty="Title" ProvideFileAsLink="false">
        <DocumentCategories>

          <DocumentCategory CategoryName="Vhodni računi" FolderName="" OverwriteFiles="true">
            <CategoryFields>
              <CategoryField FieldName="Datum" />
              <CategoryField FieldName="Vrednost" />
            </CategoryFields>
          </DocumentCategory>

          <DocumentCategory CategoryName="Zahtevek za dopust" FolderName="" OverwriteFiles="true">
            <CategoryFields>
              <CategoryField FieldName="Datum od" />
              <CategoryField FieldName="Datum do" />
            </CategoryFields>
          </DocumentCategory>

        </DocumentCategories>
    </SharePoint2010Section>
  </CustomConfiguration>

这篇关于C#WCF System.Configuration.ConfigurationErrorsException:无法识别的元素'ManagedService'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆