当前位置:  开发笔记 > 运维 > 正文

Appfabric WF4-WCF服务,如何在没有httpcontext的情况下检索codeactivity中的当前url?

如何解决《AppfabricWF4-WCF服务,如何在没有httpcontext的情况下检索codeactivity中的当前url?》经验,为你挑选了1个好方法。

我已经开发了一个带有代码活动的wf-wcf服务,并且我想要检索服务的当前URL.如果我禁用appfabric的持久性功能,我可以使用检索URL

HttpContext.Current.Request.Url.ToString()

如果启用了持久性功能,则httpcontext为null.

是否有不同的方法来检索承载我的代码活动的WCF的URL?



1> Maurice..:

您需要实现IReceiveMessageCallback并将其添加到活动的上下文中.在OnReceiveMessage中,您将传递当前的OperationContext,允许您检查传入的消息.

此 WF4示例显示了如何执行此操作.

示例代码:

using System.Activities;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activities;

namespace DeclarativeServiceLibrary2
{
    public sealed class GetWCFMessageTo : NativeActivity
    {
        public Receive Receive { get; set; }

        public OutArgument WcfTo { get; set; }

        protected override void Execute(NativeActivityContext context)
        {
            context.Properties.Add("ReceiveMessageCallback", new ReceiveMessageCallback());
            context.ScheduleActivity(Receive, CompletionCallback);
        }

        private void CompletionCallback(NativeActivityContext context, ActivityInstance completedInstance)
        {
            var receiveMessageCallback = context.Properties.Find("ReceiveMessageCallback") as ReceiveMessageCallback;
            WcfTo.Set(context, receiveMessageCallback.WcfRequestTo);
        }
    }

    [DataContract]
    class ReceiveMessageCallback : IReceiveMessageCallback
    {
        public string WcfRequestTo { get; private set; }

        public void OnReceiveMessage(OperationContext operationContext, ExecutionProperties activityExecutionProperties)
        {
            WcfRequestTo = operationContext.RequestContext.RequestMessage.Headers.To.ToString();
        }
    }
}

和示例工作流程XAMLX


  
    
      
      
      
    
    
      
        True
      
    
    
      
        
          
            
          
          
            [data]
          
        
      
    
    
      
        ["Received " & data & " WCF To header: " & WcfRequestTo]
      
    
  

推荐阅读
k78283381
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有