public Message ParseIncomingMessage(out Exception requestException) { Message message = null; Message message2; requestException = null; bool flag = true; try { this.ValidateContentType(); ServiceModelActivity activity = null; if (DiagnosticUtility.ShouldUseActivity && ((ServiceModelActivity.Current == null) || (ServiceModelActivity.Current.ActivityType != ActivityType.ProcessAction))) { activity = ServiceModelActivity.CreateBoundedActivity(true); } using (activity) { if (DiagnosticUtility.ShouldUseActivity && (activity != null)) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage); } if (!this.HasContent) { if (this.messageEncoder.MessageVersion != MessageVersion.None) { return(null); } message = new NullMessage(); } else if (this.streamed) { message = this.ReadStreamedMessage(this.InputStream); } else if (this.ContentLength == -1L) { message = this.ReadChunkedBufferedMessage(this.InputStream); } else { message = this.ReadBufferedMessage(this.InputStream); } requestException = this.ProcessHttpAddressing(message); flag = false; message2 = message; } } finally { if (flag) { this.Close(); } } return(message2); }
private ServiceModelActivity CreateCloseActivity() { ServiceModelActivity serviceModelActivity = null; serviceModelActivity = ServiceModelActivity.CreateBoundedActivity(); if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(serviceModelActivity, this.CloseActivityName, ActivityType.Close); } return(serviceModelActivity); }
private ServiceModelActivity CreateCloseActivity() { ServiceModelActivity activity = null; activity = ServiceModelActivity.CreateBoundedActivity(); if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, this.CloseActivityName, ActivityType.Close); } return(activity); }
public static ServiceModelActivity BoundDecodeOperation() { ServiceModelActivity activity = null; if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateBoundedActivity(true); ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage); } return(activity); }
ServiceModelActivity CreateCloseActivity() { ServiceModelActivity retval = null; retval = ServiceModelActivity.CreateBoundedActivity(); if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(retval, this.CloseActivityName, ActivityType.Close); } return(retval); }
public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result) { ServiceModelActivity activity = null; if (result != null) { base.TraceMessageReceived(result.RequestUri); if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(result.Application.Context)); base.StartReceiveBytesActivity(activity, result.RequestUri); } } return(activity); }
public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result) { ServiceModelActivity retval = null; if (result != null) { TraceMessageReceived(result.EventTraceActivity, result.RequestUri); if (DiagnosticUtility.ShouldUseActivity) { IServiceProvider provider = (IServiceProvider)result.Application.Context; retval = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(provider)); StartReceiveBytesActivity(retval, result.RequestUri); } } return(retval); }
private static IDisposable CreateProcessActionActivity() { IDisposable disposable = null; if (!DiagnosticUtility.ShouldUseActivity || ((ServiceModelActivity.Current != null) && (ServiceModelActivity.Current.ActivityType == ActivityType.ProcessAction))) { return(disposable); } if (((ServiceModelActivity.Current != null) && (ServiceModelActivity.Current.PreviousActivity != null)) && (ServiceModelActivity.Current.PreviousActivity.ActivityType == ActivityType.ProcessAction)) { return(ServiceModelActivity.BoundOperation(ServiceModelActivity.Current.PreviousActivity)); } ServiceModelActivity activity = ServiceModelActivity.CreateBoundedActivity(true); ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage); return(activity); }
public void OnCall() { ServiceModelActivity activity = null; try { Guid guidLogicalThreadID = Guid.Empty; if (DiagnosticUtility.ShouldUseActivity) { IComThreadingInfo comThreadingInfo; comThreadingInfo = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(ComPlusActivityTrace.IID_IComThreadingInfo); if (comThreadingInfo != null) { comThreadingInfo.GetCurrentLogicalThreadId(out guidLogicalThreadID); activity = ServiceModelActivity.CreateBoundedActivity(guidLogicalThreadID); } ServiceModelActivity.Start(activity, SR.GetString(SR.TransferringToComplus, guidLogicalThreadID.ToString()), ActivityType.TransferToComPlus); } ComPlusActivityTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationExecutingCall, SR.TraceCodeComIntegrationExecutingCall); this.callback(this.state); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } DiagnosticUtility.InvokeFinalHandler(e); } finally { if (activity != null) { activity.Dispose(); activity = null; } } }
public void OnCall() { ServiceModelActivity activity = null; try { Guid empty = Guid.Empty; if (DiagnosticUtility.ShouldUseActivity) { IComThreadingInfo info = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(ComPlusActivityTrace.IID_IComThreadingInfo); if (info != null) { info.GetCurrentLogicalThreadId(out empty); activity = ServiceModelActivity.CreateBoundedActivity(empty); } ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("TransferringToComplus", new object[] { empty.ToString() }), ActivityType.TransferToComPlus); } ComPlusActivityTrace.Trace(TraceEventType.Verbose, 0x50016, "TraceCodeComIntegrationExecutingCall"); this.callback(this.state); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } DiagnosticUtility.InvokeFinalHandler(exception); } finally { if (activity != null) { activity.Dispose(); activity = null; } } }
public ServiceHost(object singletonInstance, params Uri[] baseAddresses) { if (singletonInstance == null) { throw new ArgumentNullException("singletonInstance"); } this.singletonInstance = singletonInstance; this.serviceType = singletonInstance.GetType(); using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructServiceHost", new object[] { this.serviceType.FullName }), ActivityType.Construct); } this.InitializeDescription(singletonInstance, new UriSchemeKeyedCollection(baseAddresses)); } }
public ServiceHost(System.Type serviceType, params Uri[] baseAddresses) { if (serviceType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceType")); } this.serviceType = serviceType; using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructServiceHost", new object[] { serviceType.FullName }), ActivityType.Construct); } this.InitializeDescription(serviceType, new UriSchemeKeyedCollection(baseAddresses)); } }
public Message Receive(TimeSpan timeout) { Message message; ServiceModelActivity serviceModelActivity; SecurityMessageProperty securityMessageProperty; byte[] numArray = this.transportSettings.BufferManager.TakeBuffer(this.connection.AsyncReadBufferSize); if (this.size > 0) { Buffer.BlockCopy(this.connection.AsyncReadBuffer, this.offset, numArray, this.offset, this.size); } try { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); while (!this.DecodeBytes(numArray, ref this.offset, ref this.size, ref this.isAtEof)) { if (!this.isAtEof) { if (this.size != 0) { continue; } this.offset = 0; this.size = this.connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()); if (this.size != 0) { continue; } this.DoneReceiving(true, timeoutHelper.RemainingTime()); message = null; return(message); } else { this.DoneReceiving(true, timeoutHelper.RemainingTime()); message = null; return(message); } } Microsoft.ServiceBus.Channels.IConnection preReadConnection = this.connection; if (this.size > 0) { byte[] numArray1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.Utility.AllocateByteArray(this.size); Buffer.BlockCopy(numArray, this.offset, numArray1, 0, this.size); preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, numArray1); } Stream singletonInputConnectionStream = new Microsoft.ServiceBus.Channels.SingletonConnectionReader.SingletonInputConnectionStream(this, preReadConnection, this.transportSettings); this.inputStream = new Microsoft.ServiceBus.Channels.MaxMessageSizeStream(singletonInputConnectionStream, this.transportSettings.MaxReceivedMessageSize); if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity) { serviceModelActivity = ServiceModelActivity.CreateBoundedActivity(true); } else { serviceModelActivity = null; } using (serviceModelActivity) { Message message1 = null; try { message1 = this.transportSettings.MessageEncoderFactory.Encoder.ReadMessage(this.inputStream, this.transportSettings.MaxBufferSize, this.ContentType); } catch (XmlException xmlException1) { XmlException xmlException = xmlException1; throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(Resources.MessageXmlProtocolError, new object[0]), xmlException)); } message1.Properties.Via = this.via; MessageProperties properties = message1.Properties; if (this.security != null) { securityMessageProperty = (SecurityMessageProperty)this.security.CreateCopy(); } else { securityMessageProperty = null; } properties.Security = securityMessageProperty; this.PrepareMessage(message1); message = message1; } } finally { this.transportSettings.BufferManager.ReturnBuffer(numArray); } return(message); }
protected override Message DecodeMessage(byte[] buffer, ref int offset, ref int size, ref bool isAtEof, TimeSpan timeout) { Message message; ServiceModelActivity serviceModelActivity; while (!isAtEof && size > 0) { int num = this.decoder.Decode(buffer, offset, size); if (num > 0) { if (base.EnvelopeBuffer != null) { if (!object.ReferenceEquals(buffer, base.EnvelopeBuffer)) { Buffer.BlockCopy(buffer, offset, base.EnvelopeBuffer, base.EnvelopeOffset, num); } Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.ServerSessionConnectionReader envelopeOffset = this; envelopeOffset.EnvelopeOffset = envelopeOffset.EnvelopeOffset + num; } offset = offset + num; size = size - num; } switch (this.decoder.CurrentState) { case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.EnvelopeStart: { int envelopeSize = this.decoder.EnvelopeSize; if (envelopeSize > this.maxBufferSize) { base.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/MaxMessageSizeExceededFault", timeout); throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException((long)this.maxBufferSize)); } base.EnvelopeBuffer = this.bufferManager.TakeBuffer(envelopeSize); base.EnvelopeOffset = 0; base.EnvelopeSize = envelopeSize; continue; } case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.EnvelopeEnd: { if (base.EnvelopeBuffer == null) { continue; } if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity) { serviceModelActivity = ServiceModelActivity.CreateBoundedActivity(true); } else { serviceModelActivity = null; } using (serviceModelActivity) { Message message1 = null; try { message1 = this.messageEncoder.ReadMessage(new ArraySegment <byte>(base.EnvelopeBuffer, 0, base.EnvelopeSize), this.bufferManager, this.contentType); } catch (XmlException xmlException1) { XmlException xmlException = xmlException1; throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(Resources.MessageXmlProtocolError, new object[0]), xmlException)); } base.EnvelopeBuffer = null; message = message1; } return(message); } case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.End: { isAtEof = true; continue; } default: { continue; } } } return(null); }
public void Open(TimeSpan timeout) { if (timeout < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", System.ServiceModel.SR.GetString("SFxTimeoutOutOfRange0"))); } if (TD.CommunicationObjectOpenStartIsEnabled()) { TD.CommunicationObjectOpenStart(); } using (ServiceModelActivity activity = (DiagnosticUtility.ShouldUseActivity && this.TraceOpenAndClose) ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType); } lock (this.ThisLock) { this.ThrowIfDisposedOrImmutable(); this.state = CommunicationState.Opening; } bool flag = true; try { TimeoutHelper helper = new TimeoutHelper(timeout); this.OnOpening(); if (!this.onOpeningCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpening"), Guid.Empty, this); } this.OnOpen(helper.RemainingTime()); this.OnOpened(); if (!this.onOpenedCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpened"), Guid.Empty, this); } flag = false; } finally { if (flag) { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, 0x80005, System.ServiceModel.SR.GetString("TraceCodeCommunicationObjectOpenFailed", new object[] { this.GetCommunicationObjectType().ToString() }), this); } this.Fault(); } } } if (TD.CommunicationObjectOpenStopIsEnabled()) { TD.CommunicationObjectOpenStop(); } }
public DuplexChannelFactory(object callbackObject, Binding binding, EndpointAddress remoteAddress) : base(typeof(TChannel)) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructChannelFactory", new object[] { TraceUtility.CreateSourceString(this) }), ActivityType.Construct); } if (callbackObject == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackObject"); } if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } this.CheckAndAssignCallbackInstance(callbackObject); base.InitializeEndpoint(binding, remoteAddress); } }
public void Open(TimeSpan timeout) { if (timeout < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ArgumentOutOfRangeException("timeout", SR.GetString(SR.SFxTimeoutOutOfRange0))); } using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity && this.TraceOpenAndClose ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType); } lock (ThisLock) { ThrowIfDisposedOrImmutable(); this.state = CommunicationState.Opening; } bool throwing = true; try { TimeoutHelper actualTimeout = new TimeoutHelper(timeout); OnOpening(); if (!this.onOpeningCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpening"), Guid.Empty, this); } OnOpen(actualTimeout.RemainingTime()); OnOpened(); if (!this.onOpenedCalled) { throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpened"), Guid.Empty, this); } throwing = false; } finally { if (throwing) { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.CommunicationObjectOpenFailed, SR.GetString(SR.TraceCodeCommunicationObjectOpenFailed, this.GetCommunicationObjectType().ToString()), this); } Fault(); } } } }
// TChannel provides ContractDescription public DuplexChannelFactory(object callbackObject) : base(typeof(TChannel)) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityConstructChannelFactory, TraceUtility.CreateSourceString(this)), ActivityType.Construct); } if (callbackObject == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackObject"); } this.CheckAndAssignCallbackInstance(callbackObject); this.InitializeEndpoint((string)null, (EndpointAddress)null); } }
void ICommunicationObject.Close(TimeSpan timeout) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.Format(SR.ActivityCloseClientBase, typeof(TChannel).FullName), ActivityType.Close); } TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (_channel != null) { InnerChannel.Close(timeoutHelper.RemainingTime()); } if (!_channelFactoryRefReleased) { lock (s_staticLock) { if (!_channelFactoryRefReleased) { if (_channelFactoryRef.Release()) { _releasedLastRef = true; } _channelFactoryRefReleased = true; } } // Close the factory outside of the lock so that we can abort from a different thread. if (_releasedLastRef) { if (_useCachedFactory) { _channelFactoryRef.Abort(); } else { _channelFactoryRef.Close(timeoutHelper.RemainingTime()); } } } } }
private Task <Tuple <object, object[]> > InvokeAsync(object instance, object[] inputs) { EnsureIsInitialized(); if (instance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoServiceObject)); } if (inputs == null) { if (_inputParameterCount > 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInputParametersToServiceNull, _inputParameterCount))); } } else if (inputs.Length != _inputParameterCount) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInputParametersToServiceInvalid, _inputParameterCount, inputs.Length))); } var outputs = EmptyArray <object> .Allocate(_outputParameterCount); long beginOperation = 0; bool callSucceeded = false; bool callFaulted = false; EventTraceActivity eventTraceActivity = null; if (WcfEventSource.Instance.OperationCompletedIsEnabled() || WcfEventSource.Instance.OperationFaultedIsEnabled() || WcfEventSource.Instance.OperationFailedIsEnabled()) { beginOperation = DateTime.UtcNow.Ticks; OperationContext context = OperationContext.Current; if (context != null && context.IncomingMessage != null) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(context.IncomingMessage); } } object returnValue; try { ServiceModelActivity activity = null; IDisposable boundActivity = null; if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateBoundedActivity(true); boundActivity = activity; } else if (TraceUtility.MessageFlowTracingOnly) { Guid activityId = TraceUtility.GetReceivedActivityId(OperationContext.Current); if (activityId != Guid.Empty) { DiagnosticTraceBase.ActivityId = activityId; } } else if (TraceUtility.ShouldPropagateActivity) { //Message flow tracing only scenarios use a light-weight ActivityID management logic Guid activityId = ActivityIdHeader.ExtractActivityId(OperationContext.Current.IncomingMessage); if (activityId != Guid.Empty) { boundActivity = Activity.CreateActivity(activityId); } } using (boundActivity) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.Format(SR.ActivityExecuteMethod, _method.DeclaringType.FullName, _method.Name), ActivityType.ExecuteUserCode); } if (WcfEventSource.Instance.OperationInvokedIsEnabled()) { WcfEventSource.Instance.OperationInvoked(eventTraceActivity, MethodName, TraceUtility.GetCallerInfo(OperationContext.Current)); } returnValue = _invokeDelegate(instance, inputs, outputs); callSucceeded = true; } } catch (System.ServiceModel.FaultException) { callFaulted = true; throw; } finally { if (beginOperation != 0) { if (callSucceeded) { if (WcfEventSource.Instance.OperationCompletedIsEnabled()) { WcfEventSource.Instance.OperationCompleted(eventTraceActivity, _methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } else if (callFaulted) { if (WcfEventSource.Instance.OperationFaultedIsEnabled()) { WcfEventSource.Instance.OperationFaulted(eventTraceActivity, _methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } else { if (WcfEventSource.Instance.OperationFailedIsEnabled()) { WcfEventSource.Instance.OperationFailed(eventTraceActivity, _methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } } } return(Task.FromResult(Tuple.Create(returnValue, outputs))); }
public object Invoke(object instance, object[] inputs, out object[] outputs) { object obj2; this.EnsureIsInitialized(); if (instance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxNoServiceObject"))); } if (inputs == null) { if (this.inputParameterCount > 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInputParametersToServiceNull", new object[] { this.inputParameterCount }))); } } else if (inputs.Length != this.inputParameterCount) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInputParametersToServiceInvalid", new object[] { this.inputParameterCount, inputs.Length }))); } outputs = EmptyArray.Allocate(this.outputParameterCount); long time = 0L; long num2 = 0L; long startTicks = 0L; bool flag = false; bool flag2 = false; if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodCalled(this.MethodName); try { if (UnsafeNativeMethods.QueryPerformanceCounter(out time) == 0) { time = -1L; } } catch (SecurityException exception) { if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityException(System.ServiceModel.SR.GetString("PartialTrustPerformanceCountersNotEnabled"), exception)); } } if ((TD.OperationCompletedIsEnabled() || TD.OperationFaultedIsEnabled()) || TD.OperationFailedIsEnabled()) { startTicks = DateTime.UtcNow.Ticks; } try { ServiceModelActivity activity = null; IDisposable disposable = null; if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateBoundedActivity(true); disposable = activity; } else if (TraceUtility.MessageFlowTracingOnly) { Guid receivedActivityId = TraceUtility.GetReceivedActivityId(OperationContext.Current); if (receivedActivityId != Guid.Empty) { DiagnosticTrace.ActivityId = receivedActivityId; } } else if (TraceUtility.ShouldPropagateActivity) { Guid activityId = ActivityIdHeader.ExtractActivityId(OperationContext.Current.IncomingMessage); if (activityId != Guid.Empty) { disposable = Activity.CreateActivity(activityId); } } using (disposable) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityExecuteMethod", new object[] { this.method.DeclaringType.FullName, this.method.Name }), ActivityType.ExecuteUserCode); } if (TD.OperationInvokedIsEnabled()) { TD.OperationInvoked(this.MethodName, TraceUtility.GetCallerInfo(OperationContext.Current)); } obj2 = this.invokeDelegate(instance, inputs, outputs); flag = true; } return(obj2); } catch (FaultException) { flag2 = true; throw; } catch (SecurityException exception2) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException()); } finally { if (PerformanceCounters.PerformanceCountersEnabled) { long num4 = 0L; if ((time >= 0L) && (UnsafeNativeMethods.QueryPerformanceCounter(out num2) != 0)) { num4 = num2 - time; } if (flag) { PerformanceCounters.MethodReturnedSuccess(this.MethodName, num4); } else if (flag2) { PerformanceCounters.MethodReturnedFault(this.MethodName, num4); } else { PerformanceCounters.MethodReturnedError(this.MethodName, num4); } } if (startTicks != 0L) { if (flag) { if (TD.OperationCompletedIsEnabled()) { TD.OperationCompleted(this.methodName, TraceUtility.GetUtcBasedDurationForTrace(startTicks)); } } else if (flag2) { if (TD.OperationFaultedIsEnabled()) { TD.OperationFaulted(this.methodName, TraceUtility.GetUtcBasedDurationForTrace(startTicks)); } } else if (TD.OperationFailedIsEnabled()) { TD.OperationFailed(this.methodName, TraceUtility.GetUtcBasedDurationForTrace(startTicks)); } } } return(obj2); }
IMethodReturnMessage InvokeChannel(IMethodCallMessage methodCall) { string activityName = null; ActivityType activityType = ActivityType.Unknown; if (DiagnosticUtility.ShouldUseActivity) { if (ServiceModelActivity.Current == null || ServiceModelActivity.Current.ActivityType != ActivityType.Close) { MethodData methodData = this.GetMethodData(methodCall); if (methodData.MethodBase.DeclaringType == typeof(System.ServiceModel.ICommunicationObject) && methodData.MethodBase.Name.Equals("Close", StringComparison.Ordinal)) { activityName = SR.GetString(SR.ActivityClose, this.serviceChannel.GetType().FullName); activityType = ActivityType.Close; } } } using (ServiceModelActivity activity = string.IsNullOrEmpty(activityName) ? null : ServiceModelActivity.CreateBoundedActivity()) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, activityName, activityType); } return(ExecuteMessage(this.serviceChannel, methodCall)); } }
private IMethodReturnMessage InvokeChannel(IMethodCallMessage methodCall) { string str = null; ActivityType unknown = ActivityType.Unknown; if (DiagnosticUtility.ShouldUseActivity && ((ServiceModelActivity.Current == null) || (ServiceModelActivity.Current.ActivityType != ActivityType.Close))) { MethodData methodData = this.GetMethodData(methodCall); if ((methodData.MethodBase.DeclaringType == typeof(ICommunicationObject)) && methodData.MethodBase.Name.Equals("Close", StringComparison.Ordinal)) { str = System.ServiceModel.SR.GetString("ActivityClose", new object[] { this.serviceChannel.GetType().FullName }); unknown = ActivityType.Close; } } using (ServiceModelActivity activity = string.IsNullOrEmpty(str) ? null : ServiceModelActivity.CreateBoundedActivity()) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, str, unknown); } return(this.ExecuteMessage(this.serviceChannel, methodCall)); } }
void ICommunicationObject.Close(TimeSpan timeout) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.Format(SR.ActivityCloseClientBase, typeof(TChannel).FullName), ActivityType.Close); } TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (_channel != null) { InnerChannel.Close(timeoutHelper.RemainingTime()); } ChannelFactory.Close(timeoutHelper.RemainingTime()); } }
public Message Receive(TimeSpan timeout) { byte[] dst = DiagnosticUtility.Utility.AllocateByteArray(this.connection.AsyncReadBufferSize); if (this.size > 0) { Buffer.BlockCopy(this.connection.AsyncReadBuffer, this.offset, dst, this.offset, this.size); } TimeoutHelper helper = new TimeoutHelper(timeout); while (!this.DecodeBytes(dst, ref this.offset, ref this.size, ref this.isAtEof)) { if (this.isAtEof) { this.DoneReceiving(true, helper.RemainingTime()); return(null); } if (this.size == 0) { this.offset = 0; this.size = this.connection.Read(dst, 0, dst.Length, helper.RemainingTime()); if (this.size == 0) { this.DoneReceiving(true, helper.RemainingTime()); return(null); } } } IConnection innerConnection = this.connection; if (this.size > 0) { byte[] buffer2 = DiagnosticUtility.Utility.AllocateByteArray(this.size); Buffer.BlockCopy(dst, this.offset, buffer2, 0, this.size); innerConnection = new PreReadConnection(innerConnection, buffer2); } Stream stream = new SingletonInputConnectionStream(this, innerConnection, this.transportSettings); this.inputStream = new MaxMessageSizeStream(stream, this.transportSettings.MaxReceivedMessageSize); using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity(true) : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage); } Message message = null; try { message = this.transportSettings.MessageEncoderFactory.Encoder.ReadMessage(this.inputStream, this.transportSettings.MaxBufferSize, this.ContentType); } catch (XmlException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MessageXmlProtocolError"), exception)); } if (DiagnosticUtility.ShouldUseActivity) { TraceUtility.TransferFromTransport(message); } this.PrepareMessage(message); return(message); } }
protected override Message DecodeMessage(byte[] buffer, ref int offset, ref int size, ref bool isAtEof, TimeSpan timeout) { while (!isAtEof && (size > 0)) { int envelopeSize; int count = this.decoder.Decode(buffer, offset, size); if (count > 0) { if (base.EnvelopeBuffer != null) { if (!object.ReferenceEquals(buffer, base.EnvelopeBuffer)) { Buffer.BlockCopy(buffer, offset, base.EnvelopeBuffer, base.EnvelopeOffset, count); } base.EnvelopeOffset += count; } offset += count; size -= count; } switch (this.decoder.CurrentState) { case ServerSessionDecoder.State.EnvelopeStart: envelopeSize = this.decoder.EnvelopeSize; if (envelopeSize > this.maxBufferSize) { base.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/MaxMessageSizeExceededFault", timeout); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException((long) this.maxBufferSize)); } break; case ServerSessionDecoder.State.ReadingEnvelopeBytes: case ServerSessionDecoder.State.ReadingEndRecord: { continue; } case ServerSessionDecoder.State.EnvelopeEnd: { if (base.EnvelopeBuffer == null) { continue; } using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity(true) : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage); } Message message = null; try { message = this.messageEncoder.ReadMessage(new ArraySegment<byte>(base.EnvelopeBuffer, 0, base.EnvelopeSize), this.bufferManager, this.contentType); } catch (XmlException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MessageXmlProtocolError"), exception)); } if (DiagnosticUtility.ShouldUseActivity) { TraceUtility.TransferFromTransport(message); } base.EnvelopeBuffer = null; return message; } } case ServerSessionDecoder.State.End: goto Label_01A8; default: { continue; } } base.EnvelopeBuffer = this.bufferManager.TakeBuffer(envelopeSize); base.EnvelopeOffset = 0; base.EnvelopeSize = envelopeSize; continue; Label_01A8: isAtEof = true; } return null; }
int WbemNative.IWbemServices.PutInstanceAsync( WbemNative.IWbemClassObject wbemObject, Int32 lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink ) { if (wbemObject == null || wbemContext == null || wbemSink == null || this.wbemServices == null) { return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER); } using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { try { object val = null; int type = 0; int favor = 0; WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, ref val, ref type, ref favor)); string className = (string)val; ServiceModelActivity.Start(activity, SR.GetString(SR.WmiPutInstance, string.IsNullOrEmpty(className) ? string.Empty : className), ActivityType.WmiPutInstance); ParameterContext parms = new ParameterContext(className, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, wbemObject); IWmiProvider wmiProvider = this.GetProvider(parms.ClassName); if (wmiProvider.PutInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null)); } catch (WbemException e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed, TraceUtility.CreateSourceString(this), e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, e.ErrorCode, null, null); return(e.ErrorCode); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed, TraceUtility.CreateSourceString(this), e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null); return((int)WbemNative.WbemStatus.WBEM_E_FAILED); } finally { Marshal.ReleaseComObject(wbemSink); } } return((int)WbemNative.WbemStatus.WBEM_S_NO_ERROR); }
// TChannel provides ContractDescription, attr/config|Config object [TChannel,name] provides Binding, provide Address explicitly public ConfigurationChannelFactory(string endpointConfigurationName, Configuration configuration, EndpointAddress remoteAddress) : base(typeof(TChannel)) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityConstructChannelFactory, typeof(TChannel).FullName), ActivityType.Construct); } if (endpointConfigurationName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointConfigurationName"); } if (configuration == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("configuration"); } this.InitializeEndpoint(endpointConfigurationName, remoteAddress, configuration); } }
public object Invoke(object instance, object[] inputs, out object[] outputs) { EnsureIsInitialized(); 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))); } outputs = EmptyArray.Allocate(this.outputParameterCount); long startCounter = 0; long stopCounter = 0; long beginOperation = 0; bool callSucceeded = false; bool callFaulted = false; if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodCalled(this.MethodName); try { if (System.ServiceModel.Channels.UnsafeNativeMethods.QueryPerformanceCounter(out startCounter) == 0) { startCounter = -1; } } catch (SecurityException securityException) { DiagnosticUtility.TraceHandledException(securityException, TraceEventType.Warning); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SecurityException(SR.GetString( SR.PartialTrustPerformanceCountersNotEnabled), securityException)); } } EventTraceActivity eventTraceActivity = null; if (TD.OperationCompletedIsEnabled() || TD.OperationFaultedIsEnabled() || TD.OperationFailedIsEnabled()) { beginOperation = DateTime.UtcNow.Ticks; OperationContext context = OperationContext.Current; if (context != null && context.IncomingMessage != null) { eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(context.IncomingMessage); } } object returnValue; try { ServiceModelActivity activity = null; IDisposable boundActivity = null; if (DiagnosticUtility.ShouldUseActivity) { activity = ServiceModelActivity.CreateBoundedActivity(true); boundActivity = activity; } else if (TraceUtility.MessageFlowTracingOnly) { Guid activityId = TraceUtility.GetReceivedActivityId(OperationContext.Current); if (activityId != Guid.Empty) { DiagnosticTraceBase.ActivityId = activityId; } } else if (TraceUtility.ShouldPropagateActivity) { //Message flow tracing only scenarios use a light-weight ActivityID management logic Guid activityId = ActivityIdHeader.ExtractActivityId(OperationContext.Current.IncomingMessage); if (activityId != Guid.Empty) { boundActivity = Activity.CreateActivity(activityId); } } using (boundActivity) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityExecuteMethod, this.method.DeclaringType.FullName, this.method.Name), ActivityType.ExecuteUserCode); } if (TD.OperationInvokedIsEnabled()) { TD.OperationInvoked(eventTraceActivity, this.MethodName, TraceUtility.GetCallerInfo(OperationContext.Current)); } returnValue = this.invokeDelegate(instance, inputs, outputs); callSucceeded = true; } } catch (System.ServiceModel.FaultException) { callFaulted = true; throw; } catch (System.Security.SecurityException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException()); } finally { if (PerformanceCounters.PerformanceCountersEnabled) { long elapsedTime = 0; if (startCounter >= 0 && System.ServiceModel.Channels.UnsafeNativeMethods.QueryPerformanceCounter(out stopCounter) != 0) { elapsedTime = stopCounter - startCounter; } if (callSucceeded) // call succeeded { PerformanceCounters.MethodReturnedSuccess(this.MethodName, elapsedTime); } else if (callFaulted) // call faulted { PerformanceCounters.MethodReturnedFault(this.MethodName, elapsedTime); } else // call failed { PerformanceCounters.MethodReturnedError(this.MethodName, elapsedTime); } } if (beginOperation != 0) { if (callSucceeded) { if (TD.OperationCompletedIsEnabled()) { TD.OperationCompleted(eventTraceActivity, this.methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } else if (callFaulted) { if (TD.OperationFaultedIsEnabled()) { TD.OperationFaulted(eventTraceActivity, this.methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } else { if (TD.OperationFailedIsEnabled()) { TD.OperationFailed(eventTraceActivity, this.methodName, TraceUtility.GetUtcBasedDurationForTrace(beginOperation)); } } } } return(returnValue); }
public async Task <Message> ReceiveAsync(TimeoutHelper timeoutHelper) { byte[] buffer = Fx.AllocateByteArray(_connection.AsyncReadBufferSize); if (_size > 0) { Buffer.BlockCopy(_connection.AsyncReadBuffer, _offset, buffer, _offset, _size); } for (;;) { if (DecodeBytes(buffer, ref _offset, ref _size, ref _isAtEof)) { break; } if (_isAtEof) { DoneReceiving(true, timeoutHelper.RemainingTime()); return(null); } if (_size == 0) { _offset = 0; _size = await _connection.ReadAsync(buffer, 0, buffer.Length, timeoutHelper.RemainingTime()); if (_size == 0) { DoneReceiving(true, timeoutHelper.RemainingTime()); return(null); } } } // we're ready to read a message IConnection singletonConnection = _connection; if (_size > 0) { byte[] initialData = Fx.AllocateByteArray(_size); Buffer.BlockCopy(buffer, _offset, initialData, 0, _size); singletonConnection = new PreReadConnection(singletonConnection, initialData); } Stream connectionStream = new SingletonInputConnectionStream(this, singletonConnection, _transportSettings); _inputStream = new MaxMessageSizeStream(connectionStream, _transportSettings.MaxReceivedMessageSize); using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity(true) : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(activity, SR.Format(SR.ActivityProcessingMessage, TraceUtility.RetrieveMessageNumber()), ActivityType.ProcessMessage); } Message message = null; try { message = await _transportSettings.MessageEncoderFactory.Encoder.ReadMessageAsync( _inputStream, _transportSettings.MaxBufferSize, this.ContentType); } catch (XmlException xmlException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ProtocolException(SR.Format(SR.MessageXmlProtocolError), xmlException)); } if (DiagnosticUtility.ShouldUseActivity) { TraceUtility.TransferFromTransport(message); } PrepareMessage(message); return(message); } }