locked
Base Url of a Workflow.xamlx hosted in IIS within an CodeActivity RRS feed

  • Question

  • Is there a way to get the base URL or the complete url of a Workflow.xamlx hosted in IIS within an CodeActivity?

    thx, emikelsoft

    Monday, January 10, 2011 4:43 PM

Answers

  • Hi,

    Here is a sample code that will get the complete virtual path of xamlx workflow path:

    using System;
    using System.Activities;
    using System.Web;
    using System.Web.Hosting;

    namespace MyActivityLibrary.Test {
        public class GetPath:NativeActivity {
            public OutArgument<string> Path { getset; }      
            protected override void Execute(NativeActivityContext context) {
                string path = HostingEnvironment.MapPath("~");
                this.Path.Set(context, path);
            }
        }
    }
    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Tuesday, January 18, 2011 3:34 AM
    Thursday, January 13, 2011 2:59 AM

All replies

  • Hi,

    Here is a sample code that will get the complete virtual path of xamlx workflow path:

    using System;
    using System.Activities;
    using System.Web;
    using System.Web.Hosting;

    namespace MyActivityLibrary.Test {
        public class GetPath:NativeActivity {
            public OutArgument<string> Path { getset; }      
            protected override void Execute(NativeActivityContext context) {
                string path = HostingEnvironment.MapPath("~");
                this.Path.Set(context, path);
            }
        }
    }
    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Tuesday, January 18, 2011 3:34 AM
    Thursday, January 13, 2011 2:59 AM
  • Hi. Followup question.

    If my xalmx file is located somewhere like: MySite/MyApp/Folder/service.xamlx

    Is there a way to get a relative virtual path (in my case: 'Folder/service.xamlx') form within a code activity?

    • Proposed as answer by adnecs Friday, February 25, 2011 11:59 AM
    • Unproposed as answer by adnecs Friday, February 25, 2011 11:59 AM
    Friday, February 25, 2011 11:11 AM
  • Answering my question ;)

    Not sure if there is a better approach to the proposed one:

    - Create WCF service behavior together with configuration element.

    - Create custom workflow extensions similar to:

     public class MyExtension
      {
        private readonly string _relativePath;
        public MyExtension(string relativePath)
        {
          _relativePath = relativePath;
        }
    
        public string RelativePath
        {
          get { return _relativePath; }
        }
      }

    - for Service behavior implement the method like:

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
          var host = (WorkflowServiceHost)serviceHostBase;
          VirtualPathExtension vpExt = host.Extensions.Find<System.ServiceModel.Activation.VirtualPathExtension>();
          if(vpExt != null)
          {
            host.WorkflowExtensions.Add<MyExtension>(() => new MyExtension(vpExt.VirtualPath));
          }
        }
    

    - In your worklow you can just access your extension

     MyExtension extension = context.GetExtension<MyExtension>();
    
    • Proposed as answer by adnecs Friday, February 25, 2011 12:08 PM
    Friday, February 25, 2011 12:08 PM