RemotingServices.SetObjectUriForMarshal(MarshalByRefObject, String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets the URI for the subsequent call to the Marshal(MarshalByRefObject) method.
public:
static void SetObjectUriForMarshal(MarshalByRefObject ^ obj, System::String ^ uri);
public static void SetObjectUriForMarshal (MarshalByRefObject obj, string uri);
static member SetObjectUriForMarshal : MarshalByRefObject * string -> unit
Public Shared Sub SetObjectUriForMarshal (obj As MarshalByRefObject, uri As String)
Parameters
The object to set a URI for.
- uri
- String
The URI to assign to the specified object.
Exceptions
obj
is not a local object, has already been marshaled, or the current method has already been called on.
At least one of the callers higher in the callstack does not have permission to configure remoting types and channels.
Examples
The following code example demonstrates how to set the URI that will be used by the Marshal method when marshaling the specified object.
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Security::Permissions;
public ref class SetObjectUriForMarshalTest
{
public:
ref class TestClass: public MarshalByRefObject{};
[SecurityPermissionAttribute(SecurityAction::Demand, Flags=SecurityPermissionFlag::RemotingConfiguration)]
static void Main()
{
TestClass^ obj = gcnew TestClass;
RemotingServices::SetObjectUriForMarshal( obj, "testUri" );
RemotingServices::Marshal(obj);
Console::WriteLine( RemotingServices::GetObjectUri( obj ) );
}
};
using System;
using System.Runtime.Remoting;
public class SetObjectUriForMarshalTest {
class TestClass : MarshalByRefObject {
}
public static void Main() {
TestClass obj = new TestClass();
RemotingServices.SetObjectUriForMarshal(obj, "testUri");
RemotingServices.Marshal(obj);
Console.WriteLine(RemotingServices.GetObjectUri(obj));
}
}
Imports System.Runtime.Remoting
Imports System.Security.Permissions
Public Class SetObjectUriForMarshalTest
Class TestClass
Inherits MarshalByRefObject
End Class
<SecurityPermission(SecurityAction.Demand, Flags:= SecurityPermissionFlag.RemotingConfiguration )> _
Public Shared Sub Main()
Dim obj As TestClass = New TestClass()
RemotingServices.SetObjectUriForMarshal(obj, "testUri")
RemotingServices.Marshal(obj)
Console.WriteLine(RemotingServices.GetObjectUri(obj))
End Sub
End Class
Remarks
The URI set by the current method is used when marshaling the given object.
After marshaling, the URI of the specified object is set to the string in the uri
parameter appended onto the Guid of the current AppDomain.
If the current application is listening on an HTTP port, then both the string specified in the uri
parameter and the uri
string appended onto the Guid of the current AppDomain route to the specified object. For example, if the application is listening on HTTP port 9000, then both http://localhost:9000/objectUri
, and http://localhost:9000/<appdomainguid>/objectUri
route to the object specified in the obj
parameter.