static bool UseNoPersistHandle(NativeActivityContext executionContext) { // Default is set to true because we want NoPersistHandle to be // used if the SendReceiveExtension is not available. bool result = true; SendReceiveExtension sendReceiveExtension = executionContext.GetExtension <SendReceiveExtension>(); if (sendReceiveExtension != null) { result = sendReceiveExtension.HostSettings.UseNoPersistHandle; } return(result); }
protected override void OnUninitialize(HandleInitializationContext context) { SendReceiveExtension sendReceiveExtension = context.GetExtension <SendReceiveExtension>(); if (sendReceiveExtension != null) { if (this.InstanceKey != null) { sendReceiveExtension.OnUninitializeCorrelation(this.InstanceKey); } if (this.TransientInstanceKey != null) { sendReceiveExtension.OnUninitializeCorrelation(this.TransientInstanceKey); } } context.UninitializeHandle(this.noPersistHandle); context.UninitializeHandle(this.bookmarkScopeHandle); }
protected override void Execute(NativeActivityContext context) { MessageVersion version; SendReceiveExtension sendReceiveExtension = context.GetExtension <SendReceiveExtension>(); if (sendReceiveExtension != null) { HostSettings hostSettings = sendReceiveExtension.HostSettings; this.IncludeExceptionDetailInFaults = hostSettings.IncludeExceptionDetailInFaults; } CorrelationHandle correlatesWith = (this.CorrelatesWith == null) ? null : this.CorrelatesWith.Get(context); if (correlatesWith == null) { correlatesWith = context.Properties.Find(CorrelationHandle.StaticExecutionPropertyName) as CorrelationHandle; } CorrelationResponseContext responseContext; if (correlatesWith != null) { if (sendReceiveExtension != null) { if (!this.TryGetMessageVersion(correlatesWith.InstanceKey, out version)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.MessageVersionInformationNotFound)); } } else if (correlatesWith.TryAcquireResponseContext(context, out responseContext)) { //Register the ResponseContext so that InternalSendMessage can access it. if (!correlatesWith.TryRegisterResponseContext(context, responseContext)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.ResponseContextIsNotNull)); } //Use the same MessageVersion as the incoming message that is retrieved using CorrelatonHandle version = responseContext.MessageVersion; } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.CorrelationResponseContextShouldNotBeNull)); } } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.CorrelationResponseContextShouldNotBeNull)); } Fx.Assert((this.Formatter == null && this.FaultFormatter != null) || (this.Formatter != null && this.FaultFormatter == null), "OperationFormatter and FaultFormatter cannot be both null or both set!"); if (this.FaultFormatter != null) { Fx.Assert(this.parameters.Count == 1, "Exception should be the only parameter!"); Exception exception = this.parameters[0].Get(context) as Exception; Fx.Assert(exception != null, "InArgument must be an Exception!"); MessageFault messageFault; string action; FaultException faultException = exception as FaultException; if (faultException != null) { // This is an expected fault // Reproduce logic from ErrorBehavior.InitializeFault messageFault = this.FaultFormatter.Serialize(faultException, out action); if (action == null) { action = version.Addressing.DefaultFaultAction; } } else { // This is an unexpected fault // Reproduce logic from ErrorBehavior.ProvideFaultOfLastResort FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch); code = FaultCode.CreateReceiverFaultCode(code); action = FaultCodeConstants.Actions.NetDispatcher; if (this.IncludeExceptionDetailInFaults) { messageFault = MessageFault.CreateFault(code, new FaultReason(new FaultReasonText(exception.Message, CultureInfo.CurrentCulture)), new ExceptionDetail(exception)); } else { messageFault = MessageFault.CreateFault(code, new FaultReason(new FaultReasonText(SR2.InternalServerError, CultureInfo.CurrentCulture))); } } if (messageFault == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.CannotCreateMessageFault)); } else { Message outMessage = System.ServiceModel.Channels.Message.CreateMessage(version, messageFault, action); this.Message.Set(context, outMessage); } } else { object[] inObjects; if (this.parameters != null) { inObjects = new object[this.parameters.Count]; for (int i = 0; i < this.parameters.Count; i++) { Fx.Assert(this.Parameters[i] != null, "Parameter cannot be null"); inObjects[i] = this.parameters[i].Get(context); } } else { inObjects = Constants.EmptyArray; } object returnValue = null; if (this.Result != null) { returnValue = this.Result.Get(context); } Message outMessage = this.Formatter.SerializeReply(version, inObjects, returnValue); this.Message.Set(context, outMessage); } }
void ExecuteUsingExtension(SendReceiveExtension sendReceiveExtension, NativeActivityContext executionContext) { Fx.Assert(sendReceiveExtension != null, "SendReceiveExtension should be available here."); CorrelationHandle followingCorrelation = null; if (!this.TryGetCorrelatesWithHandle(executionContext, out followingCorrelation)) { followingCorrelation = CorrelationHandle.GetAmbientCorrelation(executionContext); if (followingCorrelation == null) { if (!this.IsOneWay) { if (!this.correlationInitializers.TryGetRequestReplyCorrelationHandle(executionContext, out followingCorrelation)) { throw FxTrace.Exception.AsError(new InvalidOperationException( SR2.ReceiveMessageNeedsToPairWithSendMessageForTwoWayContract(this.OperationName))); } } } } Bookmark bookmark = executionContext.CreateBookmark(this.OnReceiveMessageFromExtension); this.extensionReceiveBookmark.Set(executionContext, bookmark); InstanceKey correlatesWithValue = null; if (followingCorrelation != null) { if (this.IsReceiveReply && followingCorrelation.TransientInstanceKey != null) { correlatesWithValue = followingCorrelation.TransientInstanceKey; } else { correlatesWithValue = followingCorrelation.InstanceKey; } } sendReceiveExtension.RegisterReceive(this.GetReceiveSettings(), correlatesWithValue, bookmark); }