나는 내 서비스 인터페이스에 대한 다음과 같은 선언이 있습니다불일치는 계약
[AttributeUsage(AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class MyCustomContractBehavior: Attribute, IContractBehavior
을 그리고 내가 확장하는 새 서비스 인터페이스를 생성 :
[MyCustomContractBehavior]
[ServiceKnownType("GetKnownTypes", typeof(ServiceKnownTypesDiscoveryHelper))]
public interface IMyService
MyCustomContractBehavior
은 다음과 같다 내 첫 번째 인터페이스 :
public interface ITestService : IMyService
시험 중에 나는 MyCustomContractBehavior
이 작동하지 않습니다. 생성자가 호출되지만 ApplyClientBehavior
및 ApplyDispatchBehavior
이 호출되지 않습니다.
좋아, 그래서 "Inherited = true"
속성이 인터페이스 -> 클래스뿐만 아니라 인터페이스 -> 인터페이스 관계에 대해서도 작동하지 않는다고 추론했다. MyCustomContractBehavior
을 ITestService
에 추가했을 때 제대로 작동하기 시작했습니다.
하지만 나에게 와서 - 안녕하세요,하지만 ServiceKnownType
은요? 나는 ITestService
에 그것을 추가하지 않았지만 여전히 내 통합 테스트 ITestService
계약을 모두 통과했습니다! ServiceKnownType
을 IMyService
에 댓글을 달았을 때 많은 테스트가 실패했습니다. 따라서 분명히 ServiceKnownType
은 마침내 부모 인터페이스에서 "상속"됩니다.
WCF는 알려진 유형을 검색 할 때 인터페이스 계층 구조를 검사하는 것처럼 보이지만 동작을 검색 할 때 동일하게 수행하지는 않습니다. 사실인가 아니면 내가 오해하고있는 것일까?
예, 저는 IMyService와 ITestService 모두에 [ServiceContract]가 있습니다. 이상한 점은 IMyService에서만 ServiceKnownType을 가질 수 있고 ITestService에서도 "자동"으로 작동하지만 MyCustomContractBehavior 특성의 경우 ITestService에서이를 명시 적으로 설정하여 작동하도록해야한다는 것입니다. – JustAMartin