호스트와 클라이언트 모두 Net.pipe를 사용하여 동일한 프로세스에있는 FaultContracts를 지원하도록 WCF를 어떻게 구성합니까?

StackOverflow https://stackoverflow.com/questions/220401

문제

Net.pipe 바인딩을 사용하여 클라이언트 상호 작용에 대한 서비스를위한 프로세스 내 단위 테스트를 만들려고합니다. 좋은 WCF 서비스와 마찬가지로 서비스 작업에 대한 결함 구성을 사용하여 가능한 결함을 노출시킵니다. (랩핑 된 예외) 메타 데이터에. XML을 통해 클라이언트와 서비스 엔드 포인트를 구성하고 싶습니다. (App.Config). 그러나 결함이 던져 질 때마다, 그것은 단지 CommunicationException "파이프가 닫혔다"는 것입니다.

System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d). 

Net.Pipe에 IMETADATAEXCHANGE 엔드 포인트를 추가하려고 시도했지만 작동하지 않았습니다. 나는 또한 시도했다. Vista에 있으면 HTTP 엔드 포인트의 ACL을 Netsh해야했습니다. 그것도 효과가 없었습니다.

사용자 정의 예외 클래스 :

public class ValidationException : ApplicationException { }

이것은 구성에서 최신 시도이지만 펌핑됩니다. "계약 이름 'ImetadataExchange'는 서비스에서 구현 한 계약 목록에서 찾을 수 없습니다."

이 작업을 수행하는 방법에 대한 예제 또는 권장 사항에 대한 모든 링크에 감사드립니다.

<system.serviceModel>

  <client>
    <endpoint name="Client"
              contract="IService"
              address="net.pipe://localhost/ServiceTest/"
              binding="netNamedPipeBinding"
              bindingConfiguration="netPipeBindingConfig" />
  </client>

  <services>
    <service
      name="Service"
      behaviorConfiguration="ServiceFaults">
      <host>
        <baseAddresses>
          <add baseAddress="net.pipe://localhost/ServiceTest/"/>
          <add baseAddress="http://localhost/ServiceTest/"/>
        </baseAddresses>
      </host>
      <endpoint
        address=""
        binding="netNamedPipeBinding"
        bindingConfiguration="netPipeBindingConfig"

        name="ServicePipe"
        contract="IService" />
      <endpoint
        address="MEX"
        binding="mexNamedPipeBinding"
        bindingConfiguration="mexNetPipeBindingConfig"
        name="MexUserServicePipe"
        contract="IMetadataExchange" />
    </service>
  </services>

  <bindings>
    <netNamedPipeBinding>
      <binding name="netPipeBindingConfig"
               closeTimeout="00:30:00"
               sendTimeout="00:30:00" />
    </netNamedPipeBinding>
    <mexNamedPipeBinding>
      <binding name="mexNetPipeBindingConfig"></binding>
    </mexNamedPipeBinding>
  </bindings>

  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceFaults">
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
      <behavior name="MEX">
        <serviceMetadata 
          httpGetEnabled="true"
          httpGetUrl="http://localhost/ServiceTest/MEX"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

도움이 되었습니까?

해결책

위에서 설명한 ValidationException 클래스가 결함에 사용하는 클래스 인 경우 문제의 원인 일 수 있습니다. 직렬화 가능하기 때문에 Faultexception에서 결함 예외를 도출해야합니다. ApplicationException은 아닙니다.

바그너가 맞습니다. 결함 계정 속성으로 계약 유형을 제공하는 오류 정의를 장식해야합니다. 또한 DataContract 및 Datamember 속성으로 결함 계약을 장식해야합니다.

다른 팁

며칠 전에 같은 오류가 발생했습니다.
나는 내 자신의 클래스 (MyFault)를 만들고 서버에서 faultexception을 던지고 클라이언트를 잡는 것을 해결했습니다. MyFault에는 문자열 멤버가 있습니다.

나는 내가 분명하게 만들었 으면 좋겠다 ... 나는 좋은 샘플을 찾아 보려고 할 것이다.

문제는 요청 또는 응답을 필사적으로 해소하거나 직렬화하는 오류 일 가능성이 높습니다. 정확한 오류를 위해 추적을 활성화하고 svctraceviewer로 로그를보기.

또한 결함 예외에 [DataContract]가 표시되어 있고 상속 및 비 [DataContract] 클래스가 없는지 확인하십시오.

추가해야 할 마지막 한 가지. 운영 계약이 사용중인 ServiceFault를 정의합니까?.

내 이해는 운영 계층에서 사용하는 ServiceFault를 정의해야하며, 비즈니스 로직이 정의 한 ServiceFault 인 Faulexception을 던지는 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top