Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / AsyncMethodInvoker.cs / 1 / AsyncMethodInvoker.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.ServiceModel.Description; using System.Reflection; using System.ServiceModel.Diagnostics; using System.Threading; using System.Collections; using System.Diagnostics; class AsyncMethodInvoker : IOperationInvoker { MethodInfo beginMethod; MethodInfo endMethod; InvokeBeginDelegate invokeBeginDelegate; InvokeEndDelegate invokeEndDelegate; int inputParameterCount; int outputParameterCount; public AsyncMethodInvoker(MethodInfo beginMethod, MethodInfo endMethod) { if (beginMethod == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("beginMethod")); if (endMethod == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endMethod")); this.beginMethod = beginMethod; this.endMethod = endMethod; } public MethodInfo BeginMethod { get { return this.beginMethod; } } public MethodInfo EndMethod { get { return this.endMethod; } } public bool IsSynchronous { get { return false; } } public object[] AllocateInputs() { return EmptyArray.Allocate(this.InputParameterCount); } public object Invoke(object instance, object[] inputs, out object[] outputs) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } void CreateActivityInfo(ref ServiceModelActivity activity, ref Activity boundActivity) { if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateAsyncActivity(); TraceUtility.UpdateAsyncOperationContextWithActivity(activity); boundActivity = ServiceModelActivity.BoundOperation(activity, true); } else if (TraceUtility.ShouldPropagateActivity) { Guid activityId = ActivityIdHeader.ExtractActivityId(OperationContext.Current.IncomingMessage); if (activityId != Guid.Empty) { boundActivity = Activity.CreateActivity(activityId); } TraceUtility.UpdateAsyncOperationContextWithActivity(activityId); } } public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state) { if (instance == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject))); if (inputs == null) { if (this.InputParameterCount > 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceNull, this.InputParameterCount))); } else if (inputs.Length != this.InputParameterCount) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceInvalid, this.InputParameterCount, inputs.Length))); if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodCalled(beginMethod.Name.Substring(ServiceReflector.BeginMethodNamePrefix.Length)); } IAsyncResult returnValue; try { ServiceModelActivity activity = null; Activity boundActivity = null; this.CreateActivityInfo(ref activity, ref boundActivity); using (boundActivity) { if (DiagnosticUtility.ShouldUseActivity) { string activityName = null; if (this.endMethod == null) { activityName = SR.GetString(SR.ActivityExecuteMethod, this.beginMethod.DeclaringType.FullName, this.beginMethod.Name); } else { activityName = SR.GetString(SR.ActivityExecuteAsyncMethod, this.beginMethod.DeclaringType.FullName, this.beginMethod.Name, this.endMethod.DeclaringType.FullName, this.endMethod.Name); } ServiceModelActivity.Start(activity, activityName, ActivityType.ExecuteUserCode); } returnValue = this.InvokeBeginDelegate(instance, inputs, callback, state); } ServiceModelActivity.Stop(activity); } catch (System.Security.SecurityException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException()); } catch (Exception e) { TraceUtility.TraceUserCodeException(e, this.beginMethod); throw; } return returnValue; } void GetActivityInfo(ref ServiceModelActivity activity, ref Activity boundOperation) { if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity) { object activityInfo = TraceUtility.ExtractAsyncOperationContextActivity(); if (activityInfo != null) { if (DiagnosticUtility.ShouldUseActivity) { activity = activityInfo as ServiceModelActivity; boundOperation = ServiceModelActivity.BoundOperation(activity, true); } else if (TraceUtility.ShouldPropagateActivity) { if (activityInfo is Guid) { Guid activityId = (Guid)activityInfo; boundOperation = Activity.CreateActivity(activityId); } } } } } public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result) { object returnVal; if (instance == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject))); outputs = EmptyArray.Allocate(this.OutputParameterCount); bool callFailed = true; bool callFaulted = false; try { ServiceModelActivity activity = null; Activity boundOperation = null; this.GetActivityInfo(ref activity, ref boundOperation); using (boundOperation) { returnVal = this.InvokeEndDelegate(instance, outputs, result); callFailed = false; } ServiceModelActivity.Stop(activity); } catch (System.Security.SecurityException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException()); } catch (System.ServiceModel.FaultException) { callFaulted = true; callFailed = false; throw; } finally { if (PerformanceCounters.PerformanceCountersEnabled) { if (callFailed) { PerformanceCounters.MethodReturnedError(endMethod.Name.Substring(ServiceReflector.EndMethodNamePrefix.Length)); } else if (callFaulted) { PerformanceCounters.MethodReturnedFault(endMethod.Name.Substring(ServiceReflector.EndMethodNamePrefix.Length)); } else { PerformanceCounters.MethodReturnedSuccess(endMethod.Name.Substring(ServiceReflector.EndMethodNamePrefix.Length)); } } } return returnVal; } InvokeBeginDelegate InvokeBeginDelegate { get { EnsureIsInitialized(); return invokeBeginDelegate; } } InvokeEndDelegate InvokeEndDelegate { get { EnsureIsInitialized(); return invokeEndDelegate; } } int InputParameterCount { get { EnsureIsInitialized(); return this.inputParameterCount; } } int OutputParameterCount { get { EnsureIsInitialized(); return this.outputParameterCount; } } void EnsureIsInitialized() { if (this.invokeBeginDelegate == null) { // Only pass locals byref because InvokerUtil may store temporary results in the byref. // If two threads both reference this.count, temporary results may interact. int inputParameterCount; InvokeBeginDelegate invokeBeginDelegate = new InvokerUtil().GenerateInvokeBeginDelegate(this.beginMethod, out inputParameterCount); this.inputParameterCount = inputParameterCount; int outputParameterCount; InvokeEndDelegate invokeEndDelegate = new InvokerUtil().GenerateInvokeEndDelegate(this.endMethod, out outputParameterCount); this.outputParameterCount = outputParameterCount; this.invokeEndDelegate = invokeEndDelegate; this.invokeBeginDelegate = invokeBeginDelegate; // must set this last due to race } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CustomAttributeSerializer.cs
- ModelItemCollection.cs
- BasicKeyConstraint.cs
- HttpModuleAction.cs
- XmlElement.cs
- TextRangeEditTables.cs
- DbConnectionPoolCounters.cs
- SurrogateSelector.cs
- PreloadedPackages.cs
- GradientSpreadMethodValidation.cs
- DataError.cs
- ModifierKeysValueSerializer.cs
- SweepDirectionValidation.cs
- QueryableDataSourceEditData.cs
- DataGridViewTextBoxColumn.cs
- DBDataPermissionAttribute.cs
- SqlClientWrapperSmiStream.cs
- TagNameToTypeMapper.cs
- RegexStringValidatorAttribute.cs
- NativeMethods.cs
- ArrayWithOffset.cs
- CodeIndexerExpression.cs
- DetailsViewUpdateEventArgs.cs
- WebPartConnectionsCancelVerb.cs
- DetailsViewCommandEventArgs.cs
- WebBrowserContainer.cs
- AxHost.cs
- NotFiniteNumberException.cs
- Msmq3PoisonHandler.cs
- ObjectParameterCollection.cs
- PathSegment.cs
- RouteData.cs
- SchemaImporterExtension.cs
- ErrorStyle.cs
- SessionSwitchEventArgs.cs
- WindowsListViewGroupSubsetLink.cs
- SessionState.cs
- FileUtil.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- OracleTimeSpan.cs
- AssemblyResourceLoader.cs
- StrongNameKeyPair.cs
- TCPListener.cs
- StaticSiteMapProvider.cs
- GridLengthConverter.cs
- Input.cs
- PeerNameRecord.cs
- XmlDictionary.cs
- ScrollEvent.cs
- ResourceFallbackManager.cs
- ProvidersHelper.cs
- Visual3D.cs
- StoragePropertyMapping.cs
- GreenMethods.cs
- ImageSourceConverter.cs
- StructuredType.cs
- ProbeMatchesMessageCD1.cs
- AudioDeviceOut.cs
- oledbmetadatacollectionnames.cs
- LoginView.cs
- ServiceDeploymentInfo.cs
- TextServicesCompartment.cs
- CreateUserWizard.cs
- BindingsCollection.cs
- RankException.cs
- DocumentXPathNavigator.cs
- EllipseGeometry.cs
- FormattedTextSymbols.cs
- TextElementCollection.cs
- Point4D.cs
- CompilationPass2Task.cs
- Perspective.cs
- WizardPanel.cs
- UserControlParser.cs
- EdmToObjectNamespaceMap.cs
- StringCollectionEditor.cs
- DbReferenceCollection.cs
- UnaryOperationBinder.cs
- BrowserCapabilitiesFactory35.cs
- WpfGeneratedKnownTypes.cs
- SelectionPatternIdentifiers.cs
- DbConnectionPool.cs
- BigIntegerStorage.cs
- BooleanStorage.cs
- GeometryHitTestResult.cs
- Rotation3DAnimation.cs
- PeerNameRecordCollection.cs
- Configuration.cs
- StaticExtensionConverter.cs
- ReturnEventArgs.cs
- _NegotiateClient.cs
- ContentType.cs
- SoapClientProtocol.cs
- WebPartExportVerb.cs
- PointLightBase.cs
- NullableIntAverageAggregationOperator.cs
- NativeMethods.cs
- DataSourceControl.cs
- FontDifferentiator.cs
- TextInfo.cs