XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) Method

Definición

Asigna un identificador URI a un objeto que contiene el recurso real.Maps a URI to an object that contains the actual resource.

public:
 override System::Object ^ GetEntity(Uri ^ absoluteUri, System::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 Uri Uri Uri

Identificador URI devuelto desde ResolveUri(Uri, String).The URI returned from ResolveUri(Uri, String).

role
String String String String

No se usa actualmente.Currently not used.

ofObjectToReturn
Type Type Type Type

Tipo de objeto que se va a devolver.The type of object to return. La implementación actual sólo devuelve objetos Stream.The current implementation only returns Stream objects.

Devoluciones

Objeto de flujo o null si se especifica un tipo que no sea un flujo.A stream object or null if a type other than stream is specified.

Excepciones

ofObjectToReturn no es un tipo null ni Stream.ofObjectToReturn is neither null nor a Stream type.

El identificador URI especificado no es un identificador URI absoluto.The specified URI is not an absolute URI.

Se ha producido un error en tiempo de ejecución (por ejemplo, una interrupción en la conexión con el servidor).There is a runtime error (for example, an interrupted server connection).

Ejemplos

En el ejemplo siguiente se GetEntity muestran ResolveUri los métodos y.The following example demonstrates the GetEntity and ResolveUri methods.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
   Uri^ baseUri = gcnew Uri( "http://servername/tmp/test.xsl" );
   Uri^ fulluri = resolver->ResolveUri( baseUri, "includefile.xsl" );

   // Get a stream object containing the XSL file
   Stream^ s = dynamic_cast<Stream^>(resolver->GetEntity( fulluri, nullptr, Stream::typeid ));

   // Read the stream object displaying the contents of the XSL file
   XmlTextReader^ reader = gcnew XmlTextReader( s );
   while ( reader->Read() )
   {
      Console::WriteLine( reader->ReadOuterXml() );
   }
}
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

Comentarios

Este método se usa cuando el llamador desea asignar un URI determinado a un objeto que contiene el recurso que representa el URI.This method is used when the caller wants to map a given URI to an object that contains the resource that the URI represents.

Para obtener la versión asincrónica de este método, vea GetEntityAsync.For the asynchronous version of this method, see GetEntityAsync.

Importante

La aplicación puede mitigar las amenazas de denegación de servicio GetEntity de la memoria para IStream el método implementando IStream para limitar el número de bytes leídos.Your application can mitigate memory denial of service threats to the GetEntity method by implementing IStream IStream to limit the number of bytes read. Esto ayuda a protegerse frente a situaciones en las que el GetEntity código malintencionado intenta pasar una secuencia infinita de bytes al método.This helps guard against situations where malicious code attempts to pass an infinite stream of bytes to the GetEntity method.

Se aplica a

Consulte también: