2009-05-28 7 views
2

C# WebService (내부 예외로 실제 예외가있는 SoapException)에서 예외를 throw하면 클라이언트는 다음 메시지와 함께 예외를 수신합니다. 모든 HTML 항목을 억제하고 원하는 메시지로 예외를 보낼 수 있습니까?C# WebService 예외 처리

이 메시지는 전체 메시지가 아니며 제거 할 수없는 부분입니다.

The request failed with the error message: 
-- 
<html> 
    <head> 
     <title>Runtime Error</title> 
     <style> 
     body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
     p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} 
     b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} 
     H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } 
     H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } 
     pre {font-family:"Lucida Console";font-size: .9em} 
     .marker {font-weight: bold; color: black;text-decoration: none;} 
     .version {color: gray;} 
     .error {margin-bottom: 10px;} 
     .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } 
     </style> 
    </head> 

    <body bgcolor="white"> 

      <span><H1>Server Error in '/MyWeb.Service' Application.<hr width=100% size=1 color=silver></H1> 

      <h2> <i>Runtime Error</i> </h2></span> 

      <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> 

      <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed. 
      <br><br> 

      <b>Details:</b> To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".<br><br> 

      <table width=100% bgcolor="#ffffcc"> 
       <tr> 
        <td> 
         <code><pre> 

<!-- Web.Config Configuration File --> 

<configuration> 
    <system.web> 
     <customErrors mode="RemoteOnly"/> 
    </system.web> 
</configuration></pre></code> 

        </td> 
       </tr> 
      </table> 

      <br> 

      <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.<br><br> 

      <table width=100% bgcolor="#ffffcc"> 
       <tr> 
        <td> 
         <code><pre> 

<!-- Web.Config Configuration File --> 

<configuration> 
    <system.web> 
     <customErrors mode="On" defaultRedirect="mycustompage.htm"/> 
    </system.web> 
</configuration></pre></code> 

        </td> 
       </tr> 
      </table> 

      <br> 

    </body> 
</html> 

답변

1

WCF를 사용하는 경우 사용자 지정 예외를 정의 할 수 있습니다. 클라이언트가 보길 원하는 모든 예외는 FaultException 유형이어야합니다.

[DataContract] 
    public class CustomFault 
    { 
     public CustomFault() 
     { 
     } 

     public CustomFault(string message) 
     { 
      Message = message; 
     } 

     [DataMember] 
     public string Message { get; private set; } 
    } 

그리고 당신은 다음과 같이 사용자 정의 예외를 던져 :

귀하의 사용자 정의 예외는 다음과 같이 보일 것이다

throw new FaultException<CustomFault>(new CustomFault("your custom message")); 
+0

아니요, WCF를 사용하고 있지 않습니다. – crauscher

0

난 당신이 생각하고있는 오류가 있다고 생각하지 않습니다 . 귀하의 고객이 귀하의 서비스를 공격하고 웹 페이지 오류가 발생하는 것, HTML을 가져 와서 비누 예외로 포장하는 것 같습니다. 웹 서비스에 액세스 할 수 없으므로 코드를 처리 할 수있는 방법이 없습니다. 브라우저에서 WSDL을 성공적으로로드 할 수 있습니까?

+0

예외가 생성되어 WebService에 의해 throw됩니다. 그리고 그것은 SoapException입니다. – crauscher

+0

여호수아가 정확합니다. 예외 전송은 분명히 작동하거나 지난 7 년 동안 기능이 수정되었을 것입니다. 다른 무엇인가 잘못되었습니다. –

+0

@crascher : ASMX 웹 서비스는 SOAP 오류 대신 HTML을 반환합니다. 나는 그것을 보증한다. –