private void CreateHostReference()
        {
            if (OperationContext.Current != null)
            {
                ServiceHostBase serviceHostBase = OperationContext.Current.Host;

                VirtualPathExtension virtualPathExtension = serviceHostBase.Extensions.Find <VirtualPathExtension>();
                if (virtualPathExtension != null && virtualPathExtension.VirtualPath != null)
                {
                    //     HostReference Format
                    //     <SiteName><ApplicationVirtualPath>|<ServiceVirtualPath>|<ServiceName>

                    string serviceName            = serviceHostBase.Description.Name;
                    string applicationVirtualPath = HostingEnvironment.ApplicationVirtualPath;
                    string serviceVirtualPath     = virtualPathExtension.VirtualPath.Replace("~", string.Empty);

                    hostReference = string.Format("{0}{1}|{2}|{3}", HostingEnvironment.SiteName, applicationVirtualPath, serviceVirtualPath, serviceName);

                    hostReferenceIsComplete = true;
                    return;
                }
            }

            // If the entire host reference is not available, fall back to site name and app virtual path.  This will happen
            // if you try to emit a trace from outside an operation (e.g. startup) before an in operation trace has been emitted.
            hostReference = string.Format("{0}{1}", HostingEnvironment.SiteName, HostingEnvironment.ApplicationVirtualPath);
        }
Exemplo n.º 2
0
        public virtual void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            WorkflowServiceHost workflowServiceHost = serviceHostBase as WorkflowServiceHost;

            if (null != workflowServiceHost)
            {
                string workflowDisplayName = workflowServiceHost.Activity.DisplayName;
                string hostReference       = string.Empty;

                if (AspNetEnvironment.Enabled)
                {
                    VirtualPathExtension virtualPathExtension = serviceHostBase.Extensions.Find <VirtualPathExtension>();
                    if (virtualPathExtension != null && virtualPathExtension.VirtualPath != null)
                    {
                        //Format Website name\Application Virtual Path|\relative service virtual path|serviceName
                        string name        = serviceDescription != null ? serviceDescription.Name : string.Empty;
                        string application = virtualPathExtension.ApplicationVirtualPath;

                        //If the application is the root, do not include it in servicePath
                        string servicePath = virtualPathExtension.VirtualPath.Replace("~", application + "|");
                        hostReference = string.Format(CultureInfo.InvariantCulture, "{0}{1}|{2}", virtualPathExtension.SiteName, servicePath, name);
                    }
                }

                TrackingProfile trackingProfile = this.GetProfile(this.ProfileName, workflowDisplayName);
                workflowServiceHost.WorkflowExtensions.Add(
                    () => new EtwTrackingParticipant
                {
                    ApplicationReference = hostReference,
                    TrackingProfile      = trackingProfile
                });
            }
        }
        private static string GetHostReference()
        {
            if (OperationContext.Current != null)
            {
                ServiceHostBase host = OperationContext.Current.Host;
                if (host != null && host.Extensions != null)
                {
                    VirtualPathExtension extension = host.Extensions.Find <VirtualPathExtension>();
                    if (extension != null && extension.VirtualPath != null)
                    {
                        //     HostReference Format
                        //     <SiteName><ApplicationVirtualPath>|<ServiceVirtualPath>|<ServiceName>
                        string serviceName = (host.Description != null) ? host.Description.Name : string.Empty;
                        string application = HostingEnvironment.ApplicationVirtualPath;

                        string servicePath = extension.VirtualPath;
                        if (!String.IsNullOrEmpty(servicePath) && servicePath[0] == '~')
                        {
                            servicePath = application + "|" + servicePath.Substring(1);
                        }
                        return(string.Format(CultureInfo.InvariantCulture, "{0}{1}|{2}", HostingEnvironment.SiteName, servicePath, serviceName));
                    }
                }
            }

            // If the entire host reference is not available, fall back to site name and app virtual path.  This will happen
            // if you try to emit a trace from outside an operation (e.g. startup) before an in operation trace has been emitted.
            if (String.IsNullOrEmpty(DiagnosticUtility.hostReference))
            {
                DiagnosticUtility.hostReference = string.Format(CultureInfo.InvariantCulture, "{0}{1}", HostingEnvironment.SiteName, HostingEnvironment.ApplicationVirtualPath);
            }

            return(DiagnosticUtility.hostReference);
        }
Exemplo n.º 4
0
        private ChannelDispatcher BuildChannelDispatcher(Uri listenUri, ServiceHostBase host)
        {
            BindingParameterCollection parameters = new BindingParameterCollection();
            VirtualPathExtension       item       = host.Extensions.Find <VirtualPathExtension>();

            if (item != null)
            {
                parameters.Add(item);
            }

            IChannelListener <IReplyChannel> listener = null;
            WebHttpBinding binding = new WebHttpBinding();

            if (binding.CanBuildChannelListener <IReplyChannel>(parameters))
            {
                listener = binding.BuildChannelListener <IReplyChannel>(listenUri, parameters);
            }

            ChannelDispatcher channelDispatcher = new ChannelDispatcher(listener)
            {
                MessageVersion = MessageVersion.None
            };

            return(channelDispatcher);
        }
        public virtual void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            WorkflowServiceHost host = serviceHostBase as WorkflowServiceHost;

            if (host != null)
            {
                string displayName   = host.Activity.DisplayName;
                string hostReference = string.Empty;
                if (AspNetEnvironment.Enabled)
                {
                    VirtualPathExtension extension = serviceHostBase.Extensions.Find <VirtualPathExtension>();
                    if ((extension != null) && (extension.VirtualPath != null))
                    {
                        string str2 = (serviceDescription != null) ? serviceDescription.Name : string.Empty;
                        string applicationVirtualPath = extension.ApplicationVirtualPath;
                        string str4 = extension.VirtualPath.Replace("~", applicationVirtualPath + "|");
                        hostReference = string.Format(CultureInfo.InvariantCulture, "{0}{1}|{2}", new object[] { extension.SiteName, str4, str2 });
                    }
                }
                TrackingProfile trackingProfile = this.GetProfile(this.ProfileName, displayName);
                host.WorkflowExtensions.Add <EtwTrackingParticipant>(() => new EtwTrackingParticipant {
                    ApplicationReference = hostReference, TrackingProfile = trackingProfile
                });
            }
        }
Exemplo n.º 6
0
        protected override void InitializeRuntime()
        {
            VirtualPathExtension extension = this.Extensions.Find <VirtualPathExtension>();

            EventLog.WriteEntry("ASP.NET",
                                "Service virtual path is : " + extension.VirtualPath,
                                EventLogEntryType.Information);
            base.InitializeRuntime();
        }
Exemplo n.º 7
0
        public static ConnectionStringsSection GetConnectionStrings()
        {
            Configuration cfg = null;

            System.Web.HttpContext ctx = System.Web.HttpContext.Current;

            //WCF services hosted in IIS...
            VirtualPathExtension p = null;

            try
            {
                p = OperationContext.Current.Host.Extensions.Find <VirtualPathExtension>();
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (ctx != null)
                {
                    cfg = WebConfigurationManager.OpenWebConfiguration(ctx.Request.ApplicationPath);
                }
                else if (p != null)
                {
                    cfg = WebConfigurationManager.OpenWebConfiguration(p.VirtualPath);
                }
                else
                {
                    cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                }
            }
            catch (Exception ex)
            {
            }



            ConnectionStringsSection connStrings = null;

            if (cfg != null)
            {
                connStrings =
                    cfg.ConnectionStrings;
            }

            if (connStrings != null)
            {
                return(connStrings);
            }

            //final try at getting the settings:
            connStrings = ConfigurationManager.GetSection("connectionStrings") as ConnectionStringsSection;

            return(connStrings);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     获取配置
        /// </summary>
        /// <returns></returns>
        public static Configuration GetConfiguration()
        {
            string virtualPath = "~/";

            if (OperationContext.Current != null)
            {
                VirtualPathExtension extension = OperationContext.Current.Host.Extensions.Find <VirtualPathExtension>();
                virtualPath = extension.VirtualPath;
            }
            return(WebConfigurationManager.OpenWebConfiguration(virtualPath));
        }
        static bool TryGetFullVirtualPath(ServiceHostBase serviceHost, out string uri)
        {
            VirtualPathExtension pathExtension = serviceHost.Extensions.Find <VirtualPathExtension>();

            if (pathExtension == null)
            {
                uri = null;
                return(false);
            }
            uri = pathExtension.ApplicationVirtualPath + pathExtension.VirtualPath.ToString().Replace("~", "");
            return(uri != null);
        }
Exemplo n.º 10
0
        protected override void InitializeRuntime()
        {
            BindingParameterCollection bpc = new BindingParameterCollection();
            VirtualPathExtension       virtualPathExtension = this.Extensions.Find <VirtualPathExtension>();

            if (virtualPathExtension != null)
            {
                bpc.Add(virtualPathExtension);
            }

            BasicHttpBinding basicHttpBinding = new BasicHttpBinding();

            IChannelListener <IReplyChannel> listener = basicHttpBinding.BuildChannelListener <IReplyChannel>(interestedUri, bpc);

            CustomChannelDispatcher channelDispatcher = new CustomChannelDispatcher(serviceManager, listener);

            this.ChannelDispatchers.Add(channelDispatcher);
        }
Exemplo n.º 11
0
        public ConfigurationFileReader()
        {
            VirtualPathExtension virtualPathExtension = GetVirtualPathExtensionForWcfServices();

            if (HttpContext.Current != null)
            {
                // 18.02.2001 - GFI: Rettet feil som førte til at man ikke fikk installert
                //                   DIPS-WebService på Vista/IIS7 Integrated mode. Se link under for detaljer.
                // http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
                m_getConfiguration = () => WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
            }
            else if (virtualPathExtension != null)
            {
                m_getConfiguration = () => WebConfigurationManager.OpenWebConfiguration(virtualPathExtension.VirtualPath);
            }
            else if (!string.IsNullOrWhiteSpace(HttpRuntime.AppDomainAppVirtualPath))
            {
                m_getConfiguration = () => WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
            }
            else
            {
                m_getConfiguration = () =>
                {
                    try
                    {
                        return(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
                    }
                    catch (Exception)
                    {
                        var fileMap = new ExeConfigurationFileMap
                        {
                            ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
                        };
                        return(ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None));
                    }
                };
            }
        }
Exemplo n.º 12
0
        void SetScopeName()
        {
            VirtualPathExtension virtualPathExtension = this.Extensions.Find <VirtualPathExtension>();

            if (virtualPathExtension != null)
            {
                // Web Hosted scenario
                WorkflowHostingOptionsSection hostingOptions = (WorkflowHostingOptionsSection)ConfigurationManager.GetSection(ConfigurationStrings.WorkflowHostingOptionsSectionPath);
                if (hostingOptions != null && hostingOptions.OverrideSiteName)
                {
                    this.OverrideSiteName = hostingOptions.OverrideSiteName;

                    string fullVirtualPath = virtualPathExtension.VirtualPath.Substring(1);
                    fullVirtualPath = ("/" == virtualPathExtension.ApplicationVirtualPath) ? fullVirtualPath : virtualPathExtension.ApplicationVirtualPath + fullVirtualPath;

                    int    index = fullVirtualPath.LastIndexOf("/", StringComparison.OrdinalIgnoreCase);
                    string virtualDirectoryPath = fullVirtualPath.Substring(0, index + 1);

                    this.DurableInstancingOptions.ScopeName = XName.Get(XmlConvert.EncodeLocalName(Path.GetFileName(virtualPathExtension.VirtualPath)),
                                                                        string.Format(CultureInfo.InvariantCulture, "/{0}{1}", this.Description.Name, virtualDirectoryPath));
                }
            }
        }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!this.CanBuildChannelListener <TChannel>(context))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Unsupported channel type: {0}.", typeof(TChannel).Name));
            }

            UdpChannelListener channelListener = new UdpChannelListener(this, context);

            VirtualPathExtension virtualPathExtension = context.BindingParameters.Find <VirtualPathExtension>();

            if (virtualPathExtension != null)
            {
                channelListener.SetVirtualPath(virtualPathExtension.VirtualPath);
            }

            return((IChannelListener <TChannel>)(object) channelListener);
        }
 internal HostedBindingBehavior(VirtualPathExtension virtualPathExtension)
 {
     this.virtualPathExtension = virtualPathExtension;
 }
        private void CreateWorkflowManagementEndpoint(WorkflowServiceHost workflowServiceHost)
        {
            Binding          namedPipeControlEndpointBinding;
            IChannelListener listener;

            if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeNetPipe))
            {
                namedPipeControlEndpointBinding = NamedPipeControlEndpointBinding;
            }
            else if (workflowServiceHost.InternalBaseAddresses.Contains(Uri.UriSchemeHttp))
            {
                namedPipeControlEndpointBinding = HttpControlEndpointBinding;
            }
            else
            {
                return;
            }
            Uri listenUriBaseAddress        = ServiceHostBase.GetVia(namedPipeControlEndpointBinding.Scheme, new Uri("System.ServiceModel.Activities_IWorkflowInstanceManagement", UriKind.Relative), workflowServiceHost.InternalBaseAddresses);
            XmlQualifiedName   contractName = new XmlQualifiedName("IWorkflowInstanceManagement", "http://schemas.datacontract.org/2008/10/WorkflowServices");
            EndpointAddress    address      = new EndpointAddress(listenUriBaseAddress.AbsoluteUri);
            EndpointDispatcher item         = new EndpointDispatcher(address, "IWorkflowInstanceManagement", "http://schemas.datacontract.org/2008/10/WorkflowServices", true)
            {
                ContractFilter = new ActionMessageFilter(new string[] { NamingHelper.GetMessageAction(contractName, "Abandon", null, false), NamingHelper.GetMessageAction(contractName, "Cancel", null, false), NamingHelper.GetMessageAction(contractName, "Run", null, false), NamingHelper.GetMessageAction(contractName, "Suspend", null, false), NamingHelper.GetMessageAction(contractName, "Terminate", null, false), NamingHelper.GetMessageAction(contractName, "TransactedCancel", null, false), NamingHelper.GetMessageAction(contractName, "TransactedRun", null, false), NamingHelper.GetMessageAction(contractName, "TransactedSuspend", null, false), NamingHelper.GetMessageAction(contractName, "TransactedTerminate", null, false), NamingHelper.GetMessageAction(contractName, "TransactedUnsuspend", null, false), NamingHelper.GetMessageAction(contractName, "Unsuspend", null, false) })
            };
            BindingParameterCollection parameters = new BindingParameterCollection();
            VirtualPathExtension       extension  = workflowServiceHost.Extensions.Find <VirtualPathExtension>();

            if (extension != null)
            {
                parameters.Add(extension);
            }
            ChannelProtectionRequirements requirements = new ChannelProtectionRequirements();

            requirements.Add(ChannelProtectionRequirements.CreateFromContract(WorkflowControlEndpoint.WorkflowControlServiceContract, ProtectionLevel.EncryptAndSign, ProtectionLevel.EncryptAndSign, false));
            parameters.Add(requirements);
            if (namedPipeControlEndpointBinding.CanBuildChannelListener <IDuplexSessionChannel>(new object[] { listenUriBaseAddress, parameters }))
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IDuplexSessionChannel>(listenUriBaseAddress, parameters);
            }
            else if (namedPipeControlEndpointBinding.CanBuildChannelListener <IReplySessionChannel>(new object[] { listenUriBaseAddress, parameters }))
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IReplySessionChannel>(listenUriBaseAddress, parameters);
            }
            else
            {
                listener = namedPipeControlEndpointBinding.BuildChannelListener <IReplyChannel>(listenUriBaseAddress, parameters);
            }
            foreach (OperationDescription description in WorkflowControlEndpoint.WorkflowControlServiceContract.Operations)
            {
                bool flag;
                bool flag2;
                DataContractSerializerOperationBehavior behavior = new DataContractSerializerOperationBehavior(description);
                DispatchOperation operation = new DispatchOperation(item.DispatchRuntime, description.Name, NamingHelper.GetMessageAction(description, false), NamingHelper.GetMessageAction(description, true))
                {
                    Formatter = (IDispatchMessageFormatter)behavior.GetFormatter(description, out flag, out flag2, false),
                    Invoker   = new ControlOperationInvoker(description, new WorkflowControlEndpoint(namedPipeControlEndpointBinding, address), null, workflowServiceHost)
                };
                item.DispatchRuntime.Operations.Add(operation);
                OperationBehaviorAttribute attribute = description.Behaviors.Find <OperationBehaviorAttribute>();
                ((IOperationBehavior)attribute).ApplyDispatchBehavior(description, operation);
                if (attribute.TransactionScopeRequired)
                {
                    ((ITransactionChannelManager)listener).Dictionary.Add(new DirectionalAction(MessageDirection.Input, NamingHelper.GetMessageAction(description, false)), TransactionFlowOption.Allowed);
                }
            }
            DispatchRuntime dispatchRuntime = item.DispatchRuntime;

            dispatchRuntime.ConcurrencyMode             = ConcurrencyMode.Multiple;
            dispatchRuntime.InstanceContextProvider     = new DurableInstanceContextProvider(workflowServiceHost);
            dispatchRuntime.InstanceProvider            = new DurableInstanceProvider(workflowServiceHost);
            dispatchRuntime.ServiceAuthorizationManager = new WindowsAuthorizationManager(this.WindowsGroup);
            ServiceDebugBehavior     behavior2  = workflowServiceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
            ServiceBehaviorAttribute attribute2 = workflowServiceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>();
            bool flag3 = false;

            if (behavior2 != null)
            {
                flag3 |= behavior2.IncludeExceptionDetailInFaults;
            }
            if (attribute2 != null)
            {
                flag3 |= attribute2.IncludeExceptionDetailInFaults;
            }
            ChannelDispatcher dispatcher4 = new ChannelDispatcher(listener, namedPipeControlEndpointBinding.Name, namedPipeControlEndpointBinding)
            {
                MessageVersion = namedPipeControlEndpointBinding.MessageVersion
            };

            dispatcher4.Endpoints.Add(item);
            dispatcher4.ServiceThrottle = workflowServiceHost.ServiceThrottle;
            ChannelDispatcher dispatcher2 = dispatcher4;

            workflowServiceHost.ChannelDispatchers.Add(dispatcher2);
        }
Exemplo n.º 16
0
 internal virtual void ApplyHostedContext(VirtualPathExtension virtualPathExtension, bool isMetadataListener)
 {
     this.hostedVirtualPath = virtualPathExtension.VirtualPath;
 }