1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel
{
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.Runtime;
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
public class WorkflowServiceHost : ServiceHostBase
{
IList<Type> reflectedContracts;
WorkflowDefinitionContext workflowDefinitionContext;
public WorkflowServiceHost(Type workflowType, params Uri[] baseAddress) :
this(new CompiledWorkflowDefinitionContext(workflowType), baseAddress)
{
}
public WorkflowServiceHost(string workflowDefinitionPath, params Uri[] baseAddress) :
this(new StreamedWorkflowDefinitionContext(workflowDefinitionPath, null, null), baseAddress)
{
}
public WorkflowServiceHost(string workflowDefinitionPath, string ruleDefinitionPath, params Uri[] baseAddress)
: this(new StreamedWorkflowDefinitionContext(workflowDefinitionPath, ruleDefinitionPath, null), baseAddress)
{
}
public WorkflowServiceHost(string workflowDefinitionPath, string ruleDefinitionPath, ITypeProvider typeProvider, params Uri[] baseAddress)
: this(new StreamedWorkflowDefinitionContext(workflowDefinitionPath, ruleDefinitionPath, typeProvider), baseAddress)
{
}
public WorkflowServiceHost(Stream workflowDefinition, params Uri[] baseAddress) :
this(new StreamedWorkflowDefinitionContext(workflowDefinition, null, null), baseAddress)
{
}
public WorkflowServiceHost(Stream workflowDefinition, Stream ruleDefinition, params Uri[] baseAddress) :
this(new StreamedWorkflowDefinitionContext(workflowDefinition, ruleDefinition, null), baseAddress)
{
}
public WorkflowServiceHost(Stream workflowDefinition, Stream ruleDefinition, ITypeProvider typeProvider, params Uri[] baseAddress)
: this(new StreamedWorkflowDefinitionContext(workflowDefinition, ruleDefinition, typeProvider), baseAddress)
{
}
// Based on prior art from WCF:
// ServiceModel.lst:System.ServiceModel.ServiceHost..ctor(System.Object,System.Uri[])
// |DoNotCallOverridableMethodsInConstructors
// |Microsoft|By design, don't want to complicate ServiceHost state model
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
internal WorkflowServiceHost(WorkflowDefinitionContext workflowDefinitionContext, params Uri[] baseAddress)
: base()
{
InitializeDescription(workflowDefinitionContext, new UriSchemeKeyedCollection(baseAddress));
}
protected WorkflowServiceHost()
{
}
public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, string address)
{
if (address == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("address"));
}
return this.AddServiceEndpoint(implementedContract, binding, new Uri(address, UriKind.RelativeOrAbsolute));
}
public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, Uri address)
{
return this.AddServiceEndpoint(implementedContract, binding, address, null);
}
public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, string address, Uri listenUri)
{
if (address == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("address"));
}
return this.AddServiceEndpoint(implementedContract, binding, new Uri(address, UriKind.RelativeOrAbsolute), listenUri);
}
public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, Uri address, Uri listenUri)
{
if (implementedContract == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("implementedContract"));
}
if (!implementedContract.IsDefined(typeof(ServiceContractAttribute), false))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ServiceContractAttributeNotFound, new object[] { implementedContract.FullName })));
}
if (this.reflectedContracts == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractsNotInitialized, new object[] { implementedContract.FullName })));
}
if (!reflectedContracts.Contains(implementedContract))
{
if (ServiceMetadataBehavior.IsMetadataImplementedType(implementedContract))
{
if (!this.Description.Behaviors.Contains(
typeof(ServiceMetadataBehavior)))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.MetadataEndpointCannotBeAdded, new object[] { implementedContract.FullName })));
}
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractKeyNotFound, new object[] { implementedContract.FullName, this.workflowDefinitionContext.WorkflowName })));
}
}
ServiceEndpoint endpoint = base.AddServiceEndpoint(ContractDescription.GetContract(implementedContract).ConfigurationName, binding, address);
if (listenUri != null)
{
listenUri = base.MakeAbsoluteUri(listenUri, binding);
endpoint.ListenUri = listenUri;
}
return endpoint;
}
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#", Justification = "This is defined by the ServiceHost base class")]
protected override ServiceDescription CreateDescription(out IDictionary<string, ContractDescription> implementedContracts)
{
Fx.Assert(this.workflowDefinitionContext != null, "Null Workflow Definition");
return new DescriptionCreator(this.workflowDefinitionContext).BuildServiceDescription(out implementedContracts, out this.reflectedContracts);
}
protected override void OnClosing()
{
WorkflowRuntimeBehavior workflowRuntimeBehavior = this.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
if (workflowRuntimeBehavior != null)
{
workflowRuntimeBehavior.WorkflowRuntime.StopRuntime();
}
base.OnClosing();
}
void InitializeDescription(WorkflowDefinitionContext workflowDefinitionContext, UriSchemeKeyedCollection baseAddresses)
{
this.workflowDefinitionContext = workflowDefinitionContext;
this.InitializeDescription(baseAddresses);
if (!this.Description.Behaviors.Contains(typeof(WorkflowRuntimeBehavior)))
{
this.Description.Behaviors.Add(new WorkflowRuntimeBehavior());
}
}
}
}
|