Appfabric WF4-WCF 服务,如何在没有 httpcontext 的代码活动中检索当前 url? [英] Appfabric WF4-WCF services, how to retrieve current url in codeactivity without httpcontext?

查看:19
本文介绍了Appfabric WF4-WCF 服务,如何在没有 httpcontext 的代码活动中检索当前 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have developed a wf-wcf services with a code activity and in it I want to retrieve the current URL of the service. If I'm disabling the persistence feature of appfabric I can retrieve the URL using

HttpContext.Current.Request.Url.ToString()

如果启用了持久化功能,则 httpcontext 为空.

If the persistence feature is enabled then the httpcontext is null.

是否有其他方法可以检索托管我的代码活动的 WCF 的 URL?

Is there a different way to retrieve the URL of the WCF that hosts my code activity?

推荐答案

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

You need to implment IReceiveMessageCallback and add that to an activity's context. In the OnReceiveMessage you get passed the current OperationContext allowing you to inspect the incoming message.

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

This WF4 samples shows how to do this.

示例代码:

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<string> 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

and the sample workflow XAMLX

<WorkflowService mc:Ignorable="sap" ConfigurationName="Service1" sap:VirtualizedContainerService.HintSize="307,306" Name="Service1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:d="clr-namespace:DeclarativeServiceLibrary2;assembly=DeclarativeServiceLibrary2" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <p1:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="c:\temp\DeclarativeServiceLibrary2\DeclarativeServiceLibrary2\Service1.xamlx" sap:VirtualizedContainerService.HintSize="277,276" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
    <p1:Sequence.Variables>
      <p1:Variable x:TypeArguments="CorrelationHandle" Name="handle" />
      <p1:Variable x:TypeArguments="x:Int32" Name="data" />
      <p1:Variable x:TypeArguments="x:String" Name="WcfRequestTo" />
    </p1:Sequence.Variables>
    <sap:WorkflowViewStateService.ViewState>
      <scg3:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
      </scg3:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <d:GetWCFMessageTo sap:VirtualizedContainerService.HintSize="255,22" WcfTo="[WcfRequestTo]">
      <d:GetWCFMessageTo.Receive>
        <Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="255,90" OperationName="GetData" ServiceContractName="p:IService">
          <Receive.CorrelationInitializers>
            <RequestReplyCorrelationInitializer CorrelationHandle="[handle]" />
          </Receive.CorrelationInitializers>
          <ReceiveMessageContent>
            <p1:OutArgument x:TypeArguments="x:Int32">[data]</p1:OutArgument>
          </ReceiveMessageContent>
        </Receive>
      </d:GetWCFMessageTo.Receive>
    </d:GetWCFMessageTo>
    <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" sap:VirtualizedContainerService.HintSize="255,90">
      <SendMessageContent>
        <p1:InArgument x:TypeArguments="x:String">["Received " &amp; data &amp; " WCF To header: " &amp; WcfRequestTo]</p1:InArgument>
      </SendMessageContent>
    </SendReply>
  </p1:Sequence>
</WorkflowService>

这篇关于Appfabric WF4-WCF 服务,如何在没有 httpcontext 的代码活动中检索当前 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆