Tôi gặp lỗi này với tiện ích hành vi tùy chỉnh của mình mà tôi muốn thêm làm hành vi điểm cuối. Vì vậy, tôi đã chỉnh sửa lược đồ được sử dụng trong Visual Studio 2017 để loại bỏ cảnh báo trong tệp web.config của tôi.Đó là cảnh báo tương tự mà bạn đã nhận được:
Hành vi của phần tử có phần tử con không hợp lệ 'CustomSecurity'. Danh sách các phần tử có thể mong đợi: 'clientVia, callbackDebug, callbackTimeouts, clear, clientCredentials, transactedBatching, dataContractSerializer, dispatcherSynchronization, remove, synchronousReceive, webHttp, enableWebScript, endpointDiscovery, soapProcessing'.
web.config của tôi có: nút XML
<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" />
Các CustomSecurity luôn có dòng màu xanh nguệch ngoạc bên dưới nó trong Visual Studio. Nó xuất hiện dưới dạng một Cảnh báo trong cửa sổ Danh sách lỗi. Tôi muốn loại bỏ nó bởi vì mỗi lần tôi cố gắng cập nhật một tham chiếu dịch vụ, nó sẽ thất bại vì cảnh báo trong web.config.
Vì vậy, để sửa lỗi, bạn cần phải chỉnh sửa lược đồ mà Visual Studio sử dụng để xác thực các thành phần. Vì vậy, tôi đã mở web.config của mình, sau đó chọn XML trên thanh trình đơn Visual Studio chính. Sau đó chọn Schemas. Bạn sẽ nhận được một danh sách dài các lược đồ. Tìm "DotNetConfig.xsd" như bên dưới.
Duyệt tới đường dẫn được hiển thị và chỉnh sửa tệp xsd. Tìm kiếm: <xs:element name="behavior" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior">
Sau đó, thêm nút xs: element mới trong nút xs: choice với tên của tiện ích mở rộng hành vi tùy chỉnh của bạn; trong trường hợp của tôi, CustomSecurity. Lưu tập tin và Visual Studio nên xác nhận hợp lệ đối với lược đồ mới tự động và bạn sẽ không nhận được một cảnh báo trong web.config của bạn nữa.
<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
thể trùng lặp của [Hearing "element 'behavior' có phần tử con không hợp lệ" nên bỏ qua, nhưng không được cập nhật tham chiếu dịch vụ vì nó] (http://stackoverflow.com/questions/9482091/hearing-element-behavior-has-invalid- child-element-should-be-ignore-but-pr) – McGarnagle