Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Runtime / Remoting / RedirectionProxy.cs / 1 / RedirectionProxy.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // File: RedirectionProxy.cs using System; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Proxies; namespace System.Runtime.Remoting { internal class RedirectionProxy : MarshalByRefObject, IMessageSink { private MarshalByRefObject _proxy; private RealProxy _realProxy; private Type _serverType; private WellKnownObjectMode _objectMode; internal RedirectionProxy(MarshalByRefObject proxy, Type serverType) { _proxy = proxy; _realProxy = RemotingServices.GetRealProxy(_proxy); _serverType = serverType; _objectMode = WellKnownObjectMode.Singleton; } // RedirectionProxy public WellKnownObjectMode ObjectMode { set { _objectMode = value; } } // ObjectMode public virtual IMessage SyncProcessMessage(IMessage msg) { IMessage replyMsg = null; try { msg.Properties["__Uri"] = _realProxy.IdentityObject.URI; if (_objectMode == WellKnownObjectMode.Singleton) { replyMsg = _realProxy.Invoke(msg); } else { // This is a single call object, so we need to create // a new instance. MarshalByRefObject obj = (MarshalByRefObject)Activator.CreateInstance(_serverType, true); BCLDebug.Assert(RemotingServices.IsTransparentProxy(obj), "expecting a proxy"); RealProxy rp = RemotingServices.GetRealProxy(obj); replyMsg = rp.Invoke(msg); } } catch (Exception e) { replyMsg = new ReturnMessage(e, msg as IMethodCallMessage); } return replyMsg; } // SyncProcessMessage public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { // < IMessage replyMsg = null; replyMsg = SyncProcessMessage(msg); if (replySink != null) replySink.SyncProcessMessage(replyMsg); return null; } // AsyncProcessMessage public IMessageSink NextSink { get { return null; } } } // class RedirectionProxy // This is only to be used for wellknown Singleton COM objects. internal class ComRedirectionProxy : MarshalByRefObject, IMessageSink { private MarshalByRefObject _comObject; private Type _serverType; internal ComRedirectionProxy(MarshalByRefObject comObject, Type serverType) { BCLDebug.Assert(serverType.IsCOMObject, "This must be a COM object type."); _comObject = comObject; _serverType = serverType; } // ComRedirectionProxy public virtual IMessage SyncProcessMessage(IMessage msg) { IMethodCallMessage mcmReqMsg = (IMethodCallMessage)msg; IMethodReturnMessage replyMsg = null; replyMsg = RemotingServices.ExecuteMessage(_comObject, mcmReqMsg); if (replyMsg != null) { // If an "RPC server not available" (HRESULT=0x800706BA) COM // exception is thrown, we will try to recreate the object once. const int RPC_S_SERVER_UNAVAILABLE = unchecked((int)0x800706BA); const int RPC_S_CALL_FAILED_DNE = unchecked((int)0x800706BF); COMException comException = replyMsg.Exception as COMException; if ((comException != null) && ((comException._HResult == RPC_S_SERVER_UNAVAILABLE) || (comException._HResult == RPC_S_CALL_FAILED_DNE))) { _comObject = (MarshalByRefObject)Activator.CreateInstance(_serverType, true); replyMsg = RemotingServices.ExecuteMessage(_comObject, mcmReqMsg); } } return replyMsg; } // SyncProcessMessage public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { // < IMessage replyMsg = null; replyMsg = SyncProcessMessage(msg); if (replySink != null) replySink.SyncProcessMessage(replyMsg); return null; } // AsyncProcessMessage public IMessageSink NextSink { get { return null; } } } // class ComRedirectionProxy } // namespace System.Runtime.Remoting
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlElementCollection.cs
- InstanceDataCollectionCollection.cs
- COSERVERINFO.cs
- BlockUIContainer.cs
- HwndMouseInputProvider.cs
- TransactionProtocol.cs
- WebScriptMetadataInstanceContextProvider.cs
- GetWinFXPath.cs
- WebResourceUtil.cs
- DataGridRow.cs
- Hashtable.cs
- XsdDataContractExporter.cs
- ListBoxAutomationPeer.cs
- Flowchart.cs
- UIntPtr.cs
- HighlightVisual.cs
- AsyncWaitHandle.cs
- ClassValidator.cs
- TextServicesCompartment.cs
- AssemblyUtil.cs
- ManualWorkflowSchedulerService.cs
- EntityObject.cs
- RequestQueue.cs
- WebBrowsableAttribute.cs
- SqlAliaser.cs
- XPathAncestorQuery.cs
- PolicyException.cs
- SqlWorkflowPersistenceService.cs
- XmlTextReaderImpl.cs
- XPathNodeHelper.cs
- HttpDigestClientElement.cs
- OrderedEnumerableRowCollection.cs
- DbSource.cs
- Expression.DebuggerProxy.cs
- StackOverflowException.cs
- DbMetaDataFactory.cs
- RegexReplacement.cs
- InternalBufferOverflowException.cs
- HScrollProperties.cs
- ListViewDataItem.cs
- XPathNodeHelper.cs
- XPathDocumentNavigator.cs
- MimeTypeAttribute.cs
- URLString.cs
- Exceptions.cs
- PassportPrincipal.cs
- SingleKeyFrameCollection.cs
- BamlLocalizabilityResolver.cs
- SqlDataSourceCommandEventArgs.cs
- BamlRecordWriter.cs
- OracleDateTime.cs
- MetadataArtifactLoaderCompositeResource.cs
- RouteValueDictionary.cs
- SyndicationCategory.cs
- RegexTypeEditor.cs
- KeyValuePair.cs
- DocumentSchemaValidator.cs
- DesignBindingEditor.cs
- ColumnHeaderCollectionEditor.cs
- DropAnimation.xaml.cs
- DataRelationCollection.cs
- SolidBrush.cs
- TabItem.cs
- RTLAwareMessageBox.cs
- DesignerEventService.cs
- ActivityExecutorOperation.cs
- ForAllOperator.cs
- SqlDuplicator.cs
- EntityClassGenerator.cs
- AccessibleObject.cs
- HwndKeyboardInputProvider.cs
- CustomGrammar.cs
- MouseOverProperty.cs
- Metadata.cs
- ExtendLockAsyncResult.cs
- ValueConversionAttribute.cs
- DataGridRowHeaderAutomationPeer.cs
- XmlSerializableReader.cs
- ParameterModifier.cs
- Executor.cs
- ClientBuildManager.cs
- InternalSendMessage.cs
- ContentPropertyAttribute.cs
- SequenceDesigner.cs
- ListParagraph.cs
- ClientData.cs
- ReverseInheritProperty.cs
- MenuCommandsChangedEventArgs.cs
- CaseInsensitiveComparer.cs
- ReaderWriterLock.cs
- HttpCacheVary.cs
- AsyncContentLoadedEventArgs.cs
- XmlAutoDetectWriter.cs
- UntypedNullExpression.cs
- SystemInfo.cs
- AdornerPresentationContext.cs
- WorkflowDataContext.cs
- WebPartUserCapability.cs
- CacheEntry.cs
- ValidatedControlConverter.cs