XmlUrlResolver.GetEntity(Uri, String, Type) Método

Definição

Mapeia um URI para um objeto que contém o recurso real.

public:
 override System::Object ^ GetEntity(Uri ^ absoluteUri, System::String ^ role, Type ^ ofObjectToReturn);
public override object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn);
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn);
override this.GetEntity : Uri * string * Type -> obj
Public Overrides Function GetEntity (absoluteUri As Uri, role As String, ofObjectToReturn As Type) As Object

Parâmetros

absoluteUri
Uri

O URI retornado de ResolveUri(Uri, String).

role
String

Não usado no momento.

ofObjectToReturn
Type

O tipo de objeto a ser retornado. A implementação atual retorna Stream apenas objetos.

Retornos

Um objeto de fluxo ou null se um tipo diferente de fluxo for especificado.

Exceções

ofObjectToReturn não é nem null um Stream tipo.

O URI especificado não é um URI absoluto.

absoluteUri é null.

Há um erro de runtime (por exemplo, uma conexão de servidor interrompida).

Exemplos

O exemplo a seguir demonstra os métodos e GetEntity os ResolveUri métodos.

using System;
using System.IO;
using System.Xml;

 public class Sample
 {

   public static void Main()
   {
       XmlUrlResolver resolver = new XmlUrlResolver();

       Uri baseUri = new Uri ("http://servername/tmp/test.xsl");

       Uri fulluri=resolver.ResolveUri(baseUri, "includefile.xsl");

       // Get a stream object containing the XSL file
       Stream s=(Stream)resolver.GetEntity(fulluri, null, typeof(Stream));

       // Read the stream object displaying the contents of the XSL file
       XmlTextReader reader = new XmlTextReader(s);
       while (reader.Read())
       {
          Console.WriteLine(reader.ReadOuterXml());
       }
   }
}
Imports System.IO
Imports System.Xml

Public Class Sample
    
  Public Shared Sub Main()

     Dim resolver As New XmlUrlResolver()
     Dim baseUri As New Uri("http://servername/tmp/test.xsl")
     Dim fulluri As Uri = resolver.ResolveUri(baseUri, "includefile.xsl")
            
     ' Get a stream object containing the XSL file
     Dim s As Stream = CType(resolver.GetEntity(fulluri, Nothing, GetType(Stream)), Stream)
            
     ' Read the stream object displaying the contents of the XSL file
     Dim reader As New XmlTextReader(s)
     While reader.Read()
        Console.WriteLine(reader.ReadOuterXml())
     End While
        
  End Sub
End Class

Comentários

Esse método é usado quando o chamador deseja mapear um determinado URI para um objeto que contém o recurso que o URI representa.

Para obter a versão assíncrona deste método, consulte GetEntityAsync.

Importante

Seu aplicativo pode reduzir as ameaças de negação de memória de serviço ao GetEntity método implementando o IStream IStream para limitar o número de bytes lidos. Isso ajuda a proteger-se contra situações em que o código mal-intencionado tenta passar um fluxo infinito de bytes para o GetEntity método.

Aplica-se a

Confira também