Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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 // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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 // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CurrencyWrapper.cs
- cookiecollection.cs
- NumericUpDownAccelerationCollection.cs
- PreDigestedSignedInfo.cs
- DataBoundLiteralControl.cs
- PointF.cs
- GridViewSortEventArgs.cs
- dbdatarecord.cs
- ObjectQueryExecutionPlan.cs
- TemplatePagerField.cs
- ScrollChrome.cs
- PrivateFontCollection.cs
- SystemResources.cs
- VisualTreeUtils.cs
- TableAdapterManagerNameHandler.cs
- StatusStrip.cs
- PolyBezierSegment.cs
- PolyBezierSegment.cs
- TextBoxBase.cs
- Wizard.cs
- XmlAttribute.cs
- HtmlInputControl.cs
- Zone.cs
- CalendarSelectionChangedEventArgs.cs
- PrintDialog.cs
- LinkButton.cs
- Int64Converter.cs
- propertytag.cs
- _NtlmClient.cs
- HuffModule.cs
- HttpCachePolicyBase.cs
- DoubleStorage.cs
- Popup.cs
- ProjectionPlan.cs
- DrawListViewColumnHeaderEventArgs.cs
- DesignerOptionService.cs
- DataTable.cs
- streamingZipPartStream.cs
- HitTestResult.cs
- HealthMonitoringSectionHelper.cs
- ExpressionTable.cs
- SkewTransform.cs
- ActiveXHelper.cs
- ColumnReorderedEventArgs.cs
- RSAOAEPKeyExchangeDeformatter.cs
- TypeConverterHelper.cs
- PeerCollaboration.cs
- SqlExpressionNullability.cs
- MultiSelector.cs
- ResourceSet.cs
- oledbmetadatacollectionnames.cs
- PageCodeDomTreeGenerator.cs
- ClientTarget.cs
- GridViewColumn.cs
- EventPropertyMap.cs
- NativeMethods.cs
- ADRole.cs
- CollaborationHelperFunctions.cs
- ComboBoxDesigner.cs
- CodeDomLocalizationProvider.cs
- RepeatButtonAutomationPeer.cs
- DataListCommandEventArgs.cs
- CssClassPropertyAttribute.cs
- CachedPathData.cs
- Document.cs
- ToolStripContentPanel.cs
- VisualBrush.cs
- SizeF.cs
- KernelTypeValidation.cs
- SqlCommandSet.cs
- ChannelBinding.cs
- ModulesEntry.cs
- ImagingCache.cs
- GacUtil.cs
- SchemaExporter.cs
- DataGridViewCellStyle.cs
- SpeechSynthesizer.cs
- ApplicationSecurityManager.cs
- XamlSerializerUtil.cs
- DataGridViewComboBoxCell.cs
- UnmanagedMarshal.cs
- IERequestCache.cs
- IncrementalReadDecoders.cs
- DBPropSet.cs
- SqlWebEventProvider.cs
- Composition.cs
- ListViewCommandEventArgs.cs
- AuthStoreRoleProvider.cs
- IsolatedStorageFileStream.cs
- DbConnectionClosed.cs
- PenThreadWorker.cs
- _SafeNetHandles.cs
- CodeDOMUtility.cs
- Brush.cs
- SqlInfoMessageEvent.cs
- WebFormsRootDesigner.cs
- MessageSecurityProtocolFactory.cs
- Style.cs
- ListViewItemSelectionChangedEvent.cs
- EventSourceCreationData.cs