Бөлісу құралы:


Использование свойства Detail для обработки определенных ошибок

Чтобы дополнительно классифицировать исключения, службы Reporting Services возвращают другие сведения об ошибках в свойстве InnerText дочерних элементов в свойстве detail исключения SOAP. Так как свойство Detail является объектом XmlNode, с помощью приведенного ниже кода можно обращаться к внутреннему тексту дочернего элемента Message.

Список всех доступных дочерних элементов в свойстве Detail см. в разделе Свойство Detail. Дополнительные сведения см. в разделе "Подробное свойство" в документации по пакету SDK для Microsoft платформа .NET Framework.

Try  
' Code for accessing the report server  
Catch ex As SoapException  
   ' The exception is a SOAP exception, so use  
   ' the Detail property's Message element.  
   Console.WriteLine(ex.Detail("Message").InnerXml)  
End Try  
try  
{  
   // Code for accessing the report server  
}  
catch (SoapException ex)  
{  
   // The exception is a SOAP exception, so use  
   // the Detail property's Message element.  
   Console.WriteLine(ex.Detail["Message"].InnerXml);  
}  
Try  
' Code for accessing the report server  
Catch ex As SoapException  
   If ex.Detail("ErrorCode").InnerXml = "rsInvalidItemName" Then  
   End If ' Perform an action based on the specific error code  
End Try  
try  
{  
   // Code for accessing the report server  
}  
catch (SoapException ex)  
{  
   if (ex.Detail["ErrorCode"].InnerXml == "rsInvalidItemName")  
   {  
      // Perform an action based on the specific error code  
   }  
}  

Приведенная ниже строка кода выводит на консоль конкретный код ошибки, возвращенный в исключении SOAP. Можно также вычислить код ошибки и выполнить соответствующие действия.

Console.WriteLine(ex.Detail("ErrorCode").InnerXml)  
Console.WriteLine(ex.Detail["ErrorCode"].InnerXml);