2011-01-13 1 views
7

Silverlight 클라이언트 응용 프로그램의 WCF 서비스에서 정기적 인 예외를 catch하려고합니다. 이를 위해 WCF 서비스의 각 변경 사항을 in this MSDN article과 같이 포함했습니다.'behavior'요소에 wcf app.config의 'myFaultExtension'이 잘못되었습니다.

그러나 동작 확장을 구성하고 끝점 동작을 동일하게 사용할 경우 위에서 언급 한 오류가 발생하고이 오류로 인해 서비스를 실행할 수 없습니다.

여기에 제 설정이 포함되어 있습니다. 이 문제를 어떻게 해결할 수 있을까요?

<extensions> 
     <!--Add a behavior extension within the service model--> 
     <!-- Here SilverlightFaultBehavior is a class in AppServiceLib namespace --> 
     <behaviorExtensions> 
     <add name="myFaultExtension" 
      type="AppServiceLib.SilverlightFaultBehavior,AppServiceLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
     </behaviorExtensions> 
    </extensions> 
    <endpointBehaviors> 
     <behavior name="myFaultBehavior"> 
      <**myFaultExtension**/> 
     </behavior> 
    </endpointBehaviors> 
+0

http://connect.microsoft.com/VisualStudio/feedback/details/619106/wcf-fails-to-find-custom-behaviorextensionelement-if-type-attribute-doesnt-match-exactly – nologo

+0

가능한 중복 [청각 "요소 '동작'잘못된 '자식 요소가 있습니다"는 무시해야하지만 서비스 참조를 업데이트 할 수 없습니다] (http://stackoverflow.com/questions/9482091/hearing-element-behavior-has-invalid- 자식 요소가 있어야하지만 무시해야 함) – McGarnagle

답변

0
은 VS 편집기가 확장에 대해 알고하지 않습니다 때문에, WCF 구성 파일을 만들 때 Visual Studio에서이 오류가 될 수

.

하지만 이것은 런타임에서도 발생합니까 ??

이 동작을 어떻게 그리고 어디에서 사용합니까? 서버 측에서? 클라이언트 측에서? 양자 모두?

0

동일한 문제가 발생했습니다. 저를위한 해결책은 상술하는 중복 게시 Hearing "element 'behavior' has invalid child element" should be ignored, but prevented from updating service reference because of it에서 실제로 제공되었습니다. "유형"필드는 매우 민감합니다. 다른 게시물에 answer으로 언급 된 Console.WriteLine(typeof(BetterErrorMessagesFaultBehavior).AssemblyQualifiedName);을 사용하여 내가 필요한 정확한 유형을 얻을 수있었습니다.

<add name="myFaultExtension" 
     type="AppServiceLib.SilverlightFaultBehavior,AppServiceLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
+0

나를 위해 작동하지 않았다. –

+0

@Akira : 내 대답을 확인하십시오. 도움이 될 것입니다. –

2

어셈블리 컴파일/빌드 중에 어셈블리 버전이 자동 증가 될 때 문제가 발생합니다.

.NET 4.0 이후로 수정되었습니다. 버전/문화권/PublicKeyToken 이 삭제되어 config에 더 이상 자동 증가 값이 필요하지 않습니다.

<behaviorExtensions> 
    <add name="serviceKeyBehavior" 
    type="MyNamespace.ServiceKeyBehaviorExtensionElement, MyAssembly"/> 
</behaviorExtensions> 
0

오류를 방지하기 위해 편집기를 사용하여 web.config에서 WCF를 정의하십시오. (특히 전체 형명을 쓸 필요가있을 때).

오른쪽 Web.config를 클릭 한 다음 편집 WCF 구성 :

enter image description here

그런 다음으로 이동 : 고급 -> 확장 -> 동작 요소 확장 -> 새

enter image description here

그런 다음 (일반)에서 왼쪽 작은 버튼을 클릭하고 새로운 동작을 선택하십시오. app.config에 전체 유형 이름을 작성합니다.

enter image description here

지금 당신은 올바른 유형의 이름으로의 app.config에 <extensions> 태그 아래에 새 동작을 볼 수 있습니다.

1

끝점 동작으로 추가하려는 사용자 지정 동작 확장 프로그램에서이 오류가 발생했습니다. 따라서 Visual Studio 2017에서 사용 된 스키마를 편집하여 web.config 파일에서 경고를 제거했습니다.받은 경고와 동일합니다.

'behavior'요소에 잘못된 '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에서 그 아래 파란색 구불 구불 한 선을했다. 오류 목록 창에 경고로 나타납니다. 나는 Service Reference를 업데이트하려고 할 때마다 web.config의 경고 때문에 실패 할 것이기 때문에 제거하고 싶었다.

따라서 수정하려면 Visual Studio에서 요소 유효성을 검사하는 데 사용하는 스키마를 편집해야합니다.. 그래서 web.config 파일을 열고 기본 Visual Studio 메뉴 모음에서 XML을 선택했습니다. 그런 다음 스키마를 선택하십시오. 스키마 목록이 길어집니다. 아래 "DotNetConfig.xsd"를 찾으십시오. enter image description here

표시된 경로를 찾아보고 xsd 파일을 편집하십시오. 검색 대상 : <xs:element name="behavior" vs:help="configuration/system.serviceModel/behaviors/endpointBehaviors/behavior">

그런 다음 xs : choice 노드에 사용자 정의 비헤이비어 확장명과 함께 새 xs : 요소 노드를 추가하십시오. 제 경우에는 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>