UrlAttribute クラス
アセンブリ: mscorlib (mscorlib.dll 内)
![構文](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class UrlAttribute Inherits ContextAttribute
[SerializableAttribute] [ComVisibleAttribute(true)] public sealed class UrlAttribute : ContextAttribute
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class UrlAttribute sealed : public ContextAttribute
![解説](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute は、CreateInstance メソッドでアクティブなオブジェクトを作成する場合に、アクティベーション属性配列のパラメータとして Activator.CreateInstance に渡されます。
![使用例](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute を使用して、クライアント側でアクティブ化されるリモート処理を設定するコード例を次に示します。この例には、クライアント、サーバー、およびクライアントとサーバーから使用されるリモート オブジェクトの 3 つの部分が含まれます。
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Activation; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Security.Permissions; public class Client { [SecurityPermission(SecurityAction.Demand)] [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."); } }
#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.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."); } }
#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.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()."); } }
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()." ); } };
![継承階層](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
System.Attribute
System.Runtime.Remoting.Contexts.ContextAttribute
System.Runtime.Remoting.Activation.UrlAttribute
![スレッド セーフ](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![プラットフォーム](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
![バージョン情報](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)
![構文](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![例外](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![使用例](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![.NET Framework のセキュリティ](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![プラットフォーム](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
![バージョン情報](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute プロパティ
![パブリック プロパティ](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
名前 | 説明 | |
---|---|---|
![]() | Name | コンテキスト属性の名前を取得します。 ( ContextAttribute から継承されます。) |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |
![]() | UrlValue | UrlAttribute の URL 値を取得します。 |
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute メソッド
![パブリック メソッド](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
UrlAttribute メンバ
アクティブ化が発生するところで URL を指定するために、呼び出し側で使用できる属性を定義します。このクラスは継承できません。
UrlAttribute データ型で公開されるメンバを以下の表に示します。
![パブリック コンストラクタ](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![パブリック プロパティ](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
名前 | 説明 | |
---|---|---|
![]() | Name | コンテキスト属性の名前を取得します。(ContextAttribute から継承されます。) |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |
![]() | UrlValue | UrlAttribute の URL 値を取得します。 |
![パブリック メソッド](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
- UrlAttributeのページへのリンク