2011-05-16 6 views
1

나는 asimple WCF HTTP/SOAP 웹 서비스는 서비스 구현은 다음과 같이 보이는 한 예외 메시지 (즉, Hmmm, it would seem that the cogs are meshed!)는 추가 예외 세부 사항 (예 : 스택 추적)없이 호출하는 클라이언트에 리턴됩니다.WCF HTTP/SOAP WebService를 고장에서 돌아 예외 메시지는

includeExceptionDetailInFaults (서버의 web.config)을 설정하면 스택 추적과 함께 전체 예외가 반환됩니다. 그러나 false로 설정하면 일반 메시지가 표시됩니다.

서버가 내부 오류로 인해 요청을 처리하지 못했습니다. 오류에 대한 자세한 내용 IncludeExceptionDetailInFaults (ServiceBehaviorAttribute에서 또는 구성 행동에서 하나) 하기 위해 서버에 두 차례 에 다시 클라이언트를 예외 정보를 보내거나 따라 추적을 켜 Microsoft .NET Framework 3.0 SDK 설명서 및 서버 추적 로그를 검사하십시오.

문제는 SoapException 메시지를 어떻게 호출 클라이언트에 다시 가져올 수 있습니까? 예 :

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action> 
     <a:RelatesTo>urn:uuid:185719f4-6113-4126-b956-7290be375342</a:RelatesTo> 
    </s:Header> 
    <s:Body> 
     <s:Fault> 
      <s:Code> 
       <s:Value>s:Receiver</s:Value> 
       <s:Subcode> 
        <s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</s:Value> 
       </s:Subcode> 
      </s:Code> 
      <s:Reason> 
       <s:Text xml:lang="en-GB">Hmmm, it would seem that the cogs are meshed!</s:Text> 
      </s:Reason> 
     </s:Fault> 
    </s:Body> 
</s:Envelope> 

답변

2

작업에 FaultContract를 선언하고 FaultException (SoapException이 pre WCF 임)을 사용해야한다고 생각합니다. WCF가 서비스 계약에 포함되지 않은 경우 고객에게 오류를 보내지 않는다고 생각합니다. 나는 결코 SoapException을 시도한 적이 없지만 확실히 FaultException을 던지면 항상 잘 돌아갔다. 사용자 정의 예외 유형을 정의하지 않으려면

[ServiceContract()]  
public interface ISomeService 
{ 
    [OperationContract] 
    [FaultContract(typeof(MyFault))] 
    CustomResponse DoSomething(CustomRequest request) 
} 

public class SomeService 
{ 
    public CustomResponse DoSomething(CustomRequest request) 
    { 
     ... 
     throw new FaultException<MyFault>(new MyFault()); 
    } 
} 
+0

이 완벽하고도 작업에 다음과 같은 응답을 보낼 것 이렇게이

try { return InternalGubbins.WithErrorHandling.ProcessRequest(request); } catch { throw new FaultException("Hmmm, it would seem that the cogs are meshed."); } 

시도 비누 예외에서 사용자 지정 세부 정보를 사용하는 다음 질문에 대답합니다. 건배 – MrEyes

1

다음 클라이언트

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header /> 
    <s:Body> 
    <s:Fault> 
     <faultcode>s:Client</faultcode> 
     <faultstring xml:lang="en-US">Hmmm, it would seem that the cogs are meshed.</faultstring> 
    </s:Fault> 
    </s:Body> 
</s:Envelope> 
+0

그러나 완벽하게 작동하는 것 같습니다 ... Microsoft Service Trace Viewer를 사용하여 서비스 요청의 흔적을 봅니다. 어떤 이유로 FaultException을 사용할 때 추적 뷰어가 작동하지 않습니다. – MrEyes