XmlUrlResolver.GetEntity(Uri, String, Type) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
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 retornou de ResolveUri(Uri, String).
- role
- String
Atualmente não utilizado.
- ofObjectToReturn
- Type
O tipo de objeto a devolver. A implementação atual apenas devolve Stream objetos.
Devoluções
Um objeto de fluxo ou null se for especificado um tipo diferente de fluxo.
Exceções
ofObjectToReturn não é nem null um Stream tipo.
O URI especificado não é um URI absoluto.
absoluteUri é null.
Existe um erro em tempo de execução (por exemplo, uma ligação ao servidor interrompida).
Exemplos
O exemplo seguinte demonstra os GetEntity métodos e.ResolveUri
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
Observações
Este método é usado quando o chamador quer mapear um dado URI para um objeto que contém o recurso que o URI representa.
Para a versão assíncrona deste método, veja GetEntityAsync.
Importante
A sua aplicação pode mitigar ameaças de negação de serviço de memória ao GetEntity método implementando o IStream IStream para limitar o número de bytes lidos. Isso ajuda a proteger contra situações em que códigos mal-intencionados tentam passar um fluxo infinito de bytes para o GetEntity método.