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
- Part.cs
- TemplateControlBuildProvider.cs
- GroupDescription.cs
- Types.cs
- ClientUtils.cs
- SelectionEditingBehavior.cs
- SqlDataSourceQuery.cs
- OdbcParameter.cs
- PeerToPeerException.cs
- PersistenceTypeAttribute.cs
- ColorAnimationUsingKeyFrames.cs
- Tile.cs
- listviewsubitemcollectioneditor.cs
- PermissionRequestEvidence.cs
- CalculatedColumn.cs
- AlternateViewCollection.cs
- OleAutBinder.cs
- PersistenceMetadataNamespace.cs
- WeakEventManager.cs
- OptimalTextSource.cs
- SiteMapNode.cs
- EntitySqlQueryBuilder.cs
- PeerPresenceInfo.cs
- XmlFormatExtensionPrefixAttribute.cs
- PathParser.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- Publisher.cs
- CompositeActivityTypeDescriptor.cs
- Pens.cs
- SoapSchemaExporter.cs
- PartitionResolver.cs
- VectorAnimation.cs
- XmlSerializer.cs
- Token.cs
- SaveFileDialog.cs
- StreamedWorkflowDefinitionContext.cs
- XsltLibrary.cs
- CodeVariableDeclarationStatement.cs
- DataControlLinkButton.cs
- TextDecoration.cs
- FileNotFoundException.cs
- InvalidPrinterException.cs
- TransformConverter.cs
- SerializationBinder.cs
- SelectedPathEditor.cs
- TimersDescriptionAttribute.cs
- AbstractSvcMapFileLoader.cs
- GeneralTransform2DTo3DTo2D.cs
- DataQuery.cs
- ListViewDeleteEventArgs.cs
- DataBoundLiteralControl.cs
- HtmlMeta.cs
- MessageDecoder.cs
- DecoderExceptionFallback.cs
- SqlCacheDependencySection.cs
- UIElement.cs
- ChannelSinkStacks.cs
- DispatcherProcessingDisabled.cs
- DataGridCaption.cs
- CollectionViewProxy.cs
- MailMessage.cs
- TemplateXamlParser.cs
- ClientApiGenerator.cs
- TextEndOfLine.cs
- DesignerActionUI.cs
- BitmapMetadata.cs
- StringWriter.cs
- BindingOperations.cs
- GridViewColumnHeader.cs
- XmlNamespaceManager.cs
- FileStream.cs
- Partitioner.cs
- BitmapEffectDrawingContent.cs
- DataServicePagingProviderWrapper.cs
- StaticExtension.cs
- SHA256Managed.cs
- PocoPropertyAccessorStrategy.cs
- CustomErrorsSection.cs
- RelationshipManager.cs
- SqlRetyper.cs
- TextLineBreak.cs
- DataView.cs
- CodeCompileUnit.cs
- TriggerAction.cs
- RevocationPoint.cs
- PersonalizationProvider.cs
- EventSinkActivityDesigner.cs
- CompositeControl.cs
- BackStopAuthenticationModule.cs
- SoapHeader.cs
- OdbcConnectionString.cs
- _LocalDataStoreMgr.cs
- DefaultTraceListener.cs
- SessionStateItemCollection.cs
- RemotingServices.cs
- WindowsMenu.cs
- ContextProperty.cs
- ZoneIdentityPermission.cs
- SqlDuplicator.cs
- DataGridViewRow.cs