UrlAttribute Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Definierar ett attribut som kan användas på anropsplatsen för att ange den URL där aktiveringen ska ske. Det går inte att ärva den här klassen.
public ref class UrlAttribute sealed : System::Runtime::Remoting::Contexts::ContextAttribute
[System.Serializable]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class UrlAttribute : System.Runtime.Remoting.Contexts.ContextAttribute
[<System.Serializable>]
type UrlAttribute = class
inherit ContextAttribute
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type UrlAttribute = class
inherit ContextAttribute
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type UrlAttribute = class
inherit ContextAttribute
Public NotInheritable Class UrlAttribute
Inherits ContextAttribute
- Arv
- Attribut
Exempel
I följande kodexempel visas hur du konfigurerar UrlAttribute klientaktiverad fjärrkommunikation. Exemplet innehåller tre delar: en klient, en server och ett fjärrobjekt som används av klienten och servern.
I följande kodexempel visas en klient:
#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using "RemoteObject.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Activation;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
[STAThread]
int main()
{
// Report initial status.
Console::WriteLine( "Client starting." );
// Register TCP channel.
ChannelServices::RegisterChannel( gcnew TcpChannel );
// Create UrlAttribute.
UrlAttribute^ attribute = gcnew UrlAttribute( "tcp://localhost:1234/RemoteApp" );
Console::WriteLine( "UrlAttribute value: {0}", attribute->UrlValue );
array<Object^>^activationAttributes = {attribute};
// Use UrlAttribute to register for client activated remote object.
RemotingConfiguration::RegisterActivatedClientType( RemoteObject::typeid, "tcp://localhost:1234/RemoteApp" );
// Activate remote object.
Console::WriteLine( "Activating remote object." );
RemoteObject ^ obj = dynamic_cast<RemoteObject^>(Activator::CreateInstance( RemoteObject::typeid, nullptr, activationAttributes ));
// Invoke a method on it.
Console::WriteLine( "Invoking Hello() on remote object." );
obj->Hello();
// Inform user of termination.
Console::WriteLine( "Terminating client." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class Client
{
[STAThread]
public static void Main()
{
// Report the initial status.
Console.WriteLine("Starting client.");
// Register the TCP channel.
ChannelServices.RegisterChannel(new TcpChannel());
// Create a url attribute object.
UrlAttribute attribute =
new UrlAttribute("tcp://localhost:1234/RemoteApp");
Console.WriteLine("UrlAttribute value: {0}", attribute.UrlValue);
object[] activationAttributes = new object[] { attribute };
// Register the client for the remote object.
RemotingConfiguration.RegisterActivatedClientType(
typeof(RemoteObject),
"tcp://localhost:1234/RemoteApp");
// Activate the remote object.
Console.WriteLine("Activating remote object.");
RemoteObject obj = (RemoteObject) Activator.CreateInstance(
typeof(RemoteObject), null, activationAttributes);
// Invoke a method on the remote object.
Console.WriteLine("Invoking Hello() on remote object.");
obj.Hello();
// Inform the user that the program is exiting.
Console.WriteLine("The client is exiting.");
}
}
I följande kodexempel visas en server för den här klienten:
#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using "RemoteObject.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
[STAThread]
int main()
{
// Report status to user.
Console::WriteLine( "Server starting." );
// Register the TCP channel.
ChannelServices::RegisterChannel( gcnew TcpChannel( 1234 ) );
// Set application name.
RemotingConfiguration::ApplicationName = "RemoteApp";
// Register object for client activated remoting.
RemotingConfiguration::RegisterActivatedServiceType( RemoteObject::typeid );
// Wait until termination.
Console::WriteLine( "Press enter to end." );
Console::ReadLine();
Console::WriteLine( "Terminating server." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class Server
{
[STAThread]
public static void Main()
{
// Report the status to the user.
Console.WriteLine("Starting server.");
// Register the TCP channel.
ChannelServices.RegisterChannel(new TcpChannel(1234));
// Set the application name.
RemotingConfiguration.ApplicationName = "RemoteApp";
// Register the object for remoting.
RemotingConfiguration.RegisterActivatedServiceType(
typeof(RemoteObject));
// Wait until the user presses ENTER.
Console.WriteLine("Press ENTER to exit.");
Console.ReadLine();
Console.WriteLine("The server is exiting.");
}
}
I följande kodexempel visas fjärrobjektet som används av klienten och servern:
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
[assembly:AllowPartiallyTrustedCallersAttribute];
public ref class RemoteObject: public MarshalByRefObject
{
public:
RemoteObject()
{
// Report object construction to server's console.
Console::WriteLine( "You have called the constructor." );
}
void Hello()
{
// Report method invocation to server's console.
Console::WriteLine( "You have called Hello()." );
}
};
using System;
using System.Security;
using System.Security.Permissions;
public class RemoteObject : MarshalByRefObject
{
public RemoteObject()
{
Console.WriteLine("You have called the constructor.");
}
public void Hello()
{
Console.WriteLine("You have called Hello().");
}
}
Kommentarer
UrlAttribute Skickas i matrisen för aktiveringsattribut som en parameter till Activator.CreateInstance när du skapar aktiverade objekt med CreateInstance -metoden.
Mer information om hur du använder attribut finns i Attribut.
Konstruktorer
| Name | Description |
|---|---|
| UrlAttribute(String) |
Skapar en ny instans av UrlAttribute klassen. |
Fält
| Name | Description |
|---|---|
| AttributeName |
Detta API stöder produktinfrastrukturen och är inte avsett att användas direkt från koden. Anger namnet på kontextattributet. (Ärvd från ContextAttribute) |
Egenskaper
| Name | Description |
|---|---|
| Name |
Detta API stöder produktinfrastrukturen och är inte avsett att användas direkt från koden. Hämtar namnet på kontextattributet. (Ärvd från ContextAttribute) |
| TypeId |
När den implementeras i en härledd klass hämtar du en unik identifierare för den här Attribute. (Ärvd från Attribute) |
| UrlValue |
Hämtar URL-värdet för UrlAttribute. |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Kontrollerar om det angivna objektet refererar till samma URL som den aktuella instansen. |
| Freeze(Context) |
Detta API stöder produktinfrastrukturen och är inte avsett att användas direkt från koden. Anropas när kontexten är låst. (Ärvd från ContextAttribute) |
| GetHashCode() |
Returnerar hash-värdet för den aktuella UrlAttribute. |
| GetPropertiesForNewContext(IConstructionCallMessage) |
Tvingar fram skapandet av kontexten och serverobjektet i kontexten vid den angivna URL:en. |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| IsContextOK(Context, IConstructionCallMessage) |
Returnerar ett booleskt värde som anger om den angivna Context uppfyller UrlAttributekraven. |
| IsDefaultAttribute() |
När den åsidosättas i en härledd klass anger du om värdet för den här instansen är standardvärdet för den härledda klassen. (Ärvd från Attribute) |
| IsNewContextOK(Context) |
Detta API stöder produktinfrastrukturen och är inte avsett att användas direkt från koden. Returnerar ett booleskt värde som anger om kontextegenskapen är kompatibel med den nya kontexten. (Ärvd från ContextAttribute) |
| Match(Object) |
När den åsidosätts i en härledd klass returneras ett värde som anger om den här instansen är lika med ett angivet objekt. (Ärvd från Attribute) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Explicita gränssnittsimplementeringar
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mappar en uppsättning namn till en motsvarande uppsättning av sändningsidentifierare. (Ärvd från Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Hämtar typinformationen för ett objekt, som kan användas för att hämta typinformationen för ett gränssnitt. (Ärvd från Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Hämtar antalet typinformationsgränssnitt som ett objekt tillhandahåller (antingen 0 eller 1). (Ärvd från Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Ger åtkomst till egenskaper och metoder som exponeras av ett objekt. (Ärvd från Attribute) |