我有我的自定义行为扩展,我想添加为端点行为的这个错误。所以,我编辑了在Visual Studio 2017中使用的模式以摆脱web.config文件中的警告。这与您收到的警告相同:
元素'行为'具有无效的子元素'CustomSecurity'。预期可能的元素列表:'clientVia,callbackDebug,callbackTimeouts,clear,clientCredentials,transactedBatching,dataContractSerializer,dispatcherSynchronization,remove,synchronousReceive,webHttp,enableWebScript,endpointDiscovery,soapProcessing'。
我的web.config有:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="CustomSecurity"
type="FullyQualifiedPath.MyCustomBehaviorExtension, MyAssemblyName"/>
</behaviorExtensions>
</extensions>
<endpointBehaviors>
<behavior name="CustomServiceBehavior">
<CustomSecurity />
</behavior>
</endpointBehaviors>
<endpoint address="https://SomeServer/MyService.svc/soap"
behaviorConfiguration="CustomServiceBehavior" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IProject" contract="ProjectService.IProject"
name="BasicHttpBinding_IProject" />
的CustomSecurity XML节点总是有它下方的蓝色波浪线在Visual Studio。它在错误列表窗口中显示为警告。我想摆脱它,因为每次尝试更新服务引用时,都会因为web.config中的警告而失败。
所以,要解决这个问题,您需要编辑Visual Studio用于验证元素的架构。所以,我打开了我的web.config,然后在主Visual Studio菜单栏上选择了XML。然后选择模式。你会得到一个长长的模式列表。找到如下所示的“DotNetConfig.xsd”。
浏览到显示的路径并编辑xsd文件。搜索:<xs:element name="behavior" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior">
然后使用您的自定义行为扩展名称在xs:choice节点内添加一个新的xs:element节点;在我的情况下,CustomSecurity。保存该文件并且Visual Studio应该自动验证新模式,并且不应再在web.config中收到警告。
<xs:element name="behavior" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior">
<xs:complexType>
<xs:annotation>
<xs:documentation>The behavior element contains a collection of settings for the behavior of an endpoint.</xs:documentation>
</xs:annotation>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="CustomSecurity" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior/CustomSecurity">
<xs:complexType>
<xs:annotation>
<xs:documentation>Specifies the behavior extension class applied to the endpoint.</xs:documentation>
</xs:annotation>
<xs:anyAttribute namespace="http://schemas.microsoft.com/XML-Document-Transform" processContents="strict" />
</xs:complexType>
</xs:element>
<xs:element name="clientVia" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior/clientVia">
<xs:complexType>
<xs:annotation>
<xs:documentation>Specifies the URI for which the transport channel should be created.</xs:documentation>
</xs:annotation>
<xs:attribute name="viaUri" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>A string that specifies a URI that indicates the route a message should take.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="lockAttributes" type="xs:string" use="optional" />
<xs:attribute name="lockAllAttributesExcept" type="xs:string" use="optional" />
<xs:attribute name="lockElements" type="xs:string" use="optional" />
<xs:attribute name="lockAllElementsExcept" type="xs:string" use="optional" />
<xs:attribute name="lockItem" type="boolean_Type" use="optional" />
<xs:anyAttribute namespace="http://schemas.microsoft.com/XML-Document-Transform" processContents="strict" />
</xs:complexType>
</xs:element>
http://connect.microsoft.com/VisualStudio/feedback/details/619106/wcf-fails-to-find-custom-behaviorextensionelement-if-type-attribute-doesnt-match-exactly – nologo
可能重复[听力“元素'行为'具有无效的子元素”应该被忽略,但由于它更新服务引用而被阻止](http://stackoverflow.com/questions/9482091/hearing-element-behavior-has-invalid-子元素应该被忽略 - 但公关) – McGarnagle