2010-03-18 1 views
4

작업 계약에 대해 [FaultContract(typeof(ExceptionDetail))] 속성을 넣었습니다. 클라이언트 응용 프로그램에 서비스를 추가하려고하면이 오류가 발생합니다. "Custom tool error: Failed to generate code for the service reference 'ServiceReference1'. Please check other error and warning messages for details."WCF : FaultContract (typeof (ExceptionDetail)) 문제

그러나 FaultContract 특성을 주석 처리 할 때 클라이언트 응용 프로그램에 wcf 서비스 참조를 추가 할 수 있습니다.

답변

2

FaultContract 제거하고 대신 includeExceptionDetailInFaults을 구성

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Behavior"> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
+0

동일한 설정을 사용하고 있습니다. – user296598

+0

@jitus :이 경우 예외를 나열 할 필요가 없습니다. –

+0

[MSDN] (https://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.includeexceptiondetailinfaults%28v=vs.110%29.aspx)에 따르면 이는 디버깅에만 권장됩니다. 나는 왜 그런지 말할 수 없다. – LosManos

9

가진 FaultContracts의 요점은 그것을 가능하게하는 우선의 사이의 통신 채널을 중단하지 않습니다 서비스에서 다시 SOAP 오류를 전달하는 것입니다 서버 및 클라이언트 (.NET 예외와 같은 오류 조건을 정상적으로 상호 운용 가능)를 처리하고 두 번째로 FaultContracts를 사용하여 유형 오류 (FaultException<T>)를 던지기보다는 서버에서 클라이언트를 잡을 수 있습니다. 당신이 원하는 또는 정말 상호 운용이 가능해야하는 경우

을 수행해야합니다

  • 은 [DataContract] 속성
  • 캐치로 장식 클래스로 모든 FaultContract 유형을 정의 서버의 모든 .NET 예외 (모든 .NET은 처리, 서버 : 예 IErrorHandler 인터페이스를 사용)하고 와이어의 양쪽 끝을 제어하고 양쪽 끝은 당신이 한 단계하여이 작업을 단순화 할 수 있습니다, .NET 경우 상호 SOAP 오류

로 차례 예외를 설정하고 예를 들어 FaultException<ArgumentOutOfRangeException>이, 즉, "(어떤 .NET 예외)의 고장"는를 만든 다음 클라이언트에서, 그 입력 오류 예외가 잡아 그들을 처리 : 다음

[FaultContract(typeof(ArgumentOutOfRangeException)] 
[OperationContract] 
public void CallService(.......) 

및 구현에, 이것을 사용 :

try 
{ 
    clientProxy.CallService(); 
} 
catch(FaultException<ArgumentOutOfRangeException> ex) 
{ 
    // handle the most specific exception first 
} 
catch(FaultException ex) 
{ 
    // handle all other, unspecific server faults 
} 
catch(CommunicationException ex) 
{ 
    // handle all other, client-proxy related WCF errors 
} 
catch(Exception ex) 
{ 
    // handle anything else.... 
} 
0

몇 분 전에 동일한 문제가있었습니다. 기본 생성자가 없기 때문입니다. 또한 모든 속성에는 public get/set 접근자가 있어야합니다.