잘못된 요청 방지

애플리케이션 흐름을 분석하고 보고서 서버로 전송되는 요청이 유효한지 확인하여 일부 유형의 예외가 throw되는 것을 방지할 수 있습니다. 예를 들어 사용자가 보고서, 데이터 원본 또는 기타 보고서 서버 항목의 이름을 추가하거나 업데이트할 수 있는 애플리케이션이 있을 수 있습니다. 이 경우 사용자가 입력할 수 있는 텍스트의 유효성을 검사해야 합니다. 또한 요청을 보고서 서버로 보내기 전에 항상 예약 문자를 확인해야 합니다. 코드에서 조건 부 if 문 또는 기타 논리 구문을 사용하여 사용자에게 보고서 서버로 요청을 보내는 데 필요한 조건을 충족하지 못했음을 알릴 수 있습니다.

다음의 간단한 C# 예에서는 사용자가 이름에 슬래시(/) 문자가 포함된 보고서를 만들려고 시도할 때 오류 메시지를 표시합니다.

// C#  
private void PublishReport()  
{  
   int index;  
   string reservedChar;  
   string message;  
  
   // Check the text value of the name text box for "/",  
   // a reserved character  
   index = nameTextBox.Text.IndexOf(@"/");  
  
   if ( index != -1) // The text contains the character  
   {  
      reservedChar = nameTextBox.Text.Substring(index, 1);  
      // Build a user-friendly error message  
      message = "The name of the report cannot contain the reserved character " +  
         "\"" + reservedChar + "\". " +  
         "Please enter a valid name for the report. " +  
         "For more information about reserved characters, " +  
         "see the help documentation";  
  
      MessageBox.Show(message, "Invalid Input Error");  
   }  
   else // Publish the report  
   {  
      Byte[] definition = null;  
      Warning[] warnings = {};  
      string name = nameTextBox.Text;  
  
      FileStream stream = File.OpenRead("MyReport.rdl");  
      definition = new Byte[stream.Length];  
      stream.Read(definition, 0, (int) stream.Length);  
      stream.Close();  
      // Create report with user-defined name  
      rs.CreateCatalogItem("Report", name, "/Samples", false, definition, null, out warnings);  
      MessageBox.Show("Report: {0} created successfully", name);  
   }  
}  

요청이 보고서 서버로 전송되기 전에 방지할 수 있는 오류 유형에 대한 자세한 내용은 SoapException 오류 테이블을 참조 하세요. try/catch 블록을 사용하여 이전 예제를 향상시키는 방법에 대한 자세한 내용은 try 및 catch 블록 사용을 참조하세요.

Reporting Services의 예외 관리 소개
Reporting Services SoapException 클래스