在WCF服务应用程序中使用企业库时,当我们尝试对通过引用传入参数的操作使用验证时,我们会遇到以下异常:
运营合同:
Hubs GetRoute(
string sourceDepotId,
[NotNullValidator(MessageTemplate = "...")]
[RegexValidator("[a-zA-Z]", MessageTemplate = "...")]
[StringLengthValidator(2, RangeBoundaryType.Inclusive, 2, RangeBoundaryType.Inclusive, MessageTemplate = "...")]
string countryCode,
string zipCode,
DateTime shippingDate,
DateTime? deliveryDate,
ref RoutingCodes routingCode,
out string errorMessage);
例外:
类型' RoutingCodes&'不得用作类型参数。
[ArgumentException: The type 'RoutingCodes&' may not be used as a type argument.]
System.RuntimeType.ThrowIfTypeNeverValidGenericArgument(RuntimeType type) +14240432
System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters) +57
System.RuntimeType.MakeGenericType(Type[] instantiation) +218
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.WrapAndInstrumentValidator(Validator validator, Type type) +87
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.FindOrCreateValidator(ValidatorCacheKey cacheKey, Func`3 wrapAndInstrument) +190
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.CreateValidator(Type targetType, String ruleset) +176
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationParameterInspector.CreateInputParameterValidator(ParameterInfo param, String ruleSet) +99
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationParameterInspector..ctor(OperationDescription operation, String ruleSet) +221
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationBehavior.ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime) +161
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +5106
System.ServiceModel.ServiceHostBase.InitializeRuntime() +85
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +48
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +293
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +129
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +733
所述类型是枚举类型。我知道你实际上可以在WCF中通过ref传递参数并且它可以工作,如documentation中所述。
这是企业资源库验证区中的错误还是我们做错了什么?除了不使用验证块之外,你如何规避异常?