/// <summary> /// Initializes a new <see cref="ServiceOperation"/> instance. /// </summary> /// <param name="name">name of the service operation.</param> /// <param name="resultKind">Kind of result expected from this operation.</param> /// <param name="resultType">Type of element of the method result.</param> /// <param name="resultSet">EntitySet of the result expected from this operation.</param> /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param> /// <param name="parameters">In-order parameters for this operation.</param> public ServiceOperation( string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNull(method, "method"); if ((resultKind == ServiceOperationResultKind.Void && resultType != null) || (resultKind != ServiceOperationResultKind.Void && resultType == null)) { throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void)); } if ((resultType == null || resultType.ResourceTypeKind != ResourceTypeKind.EntityType) && resultSet != null) { throw new ArgumentException(Strings.ServiceOperation_ResultSetMustBeNull("resultSet", "resultType")); } if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultSet == null || !resultSet.ResourceType.IsAssignableFrom(resultType))) { throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet")); } if (method != XmlConstants.HttpMethodGet && method != XmlConstants.HttpMethodPost) { throw new ArgumentException(Strings.ServiceOperation_NotSupportedProtocolMethod(method, name)); } this.name = name; this.resultKind = resultKind; this.resultType = resultType; this.resourceSet = resultSet; this.method = method; if (parameters == null) { this.parameters = ServiceOperation.emptyParameterCollection; } else { this.parameters = new ReadOnlyCollection <ServiceOperationParameter>(new List <ServiceOperationParameter>(parameters)); HashSet <string> paramNames = new HashSet <string>(StringComparer.Ordinal); foreach (ServiceOperationParameter p in this.parameters) { if (!paramNames.Add(p.Name)) { throw new ArgumentException(Strings.ServiceOperation_DuplicateParameterName(p.Name), "parameters"); } } } }
internal Operation(string name, ServiceOperationResultKind resultKind, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable <OperationParameter> parameters, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNullOrEmpty(method, "method"); ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind); this.name = name; this.resultKind = resultKind; this.returnType = returnType; this.resourceSet = resultSet; this.resultSetPathExpression = resultSetPathExpression; this.method = method; this.kind = kind; this.operationParameterBindingKind = operationParameterBindingKind; this.operationParameters = ValidateParameters(this.operationParameterBindingKind, parameters); if (this.operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never) { this.bindingParameter = this.operationParameters.FirstOrDefault <OperationParameter>(); if (this.bindingParameter == null) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind"); } if (((resultSetPathExpression != null) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression")); } if (((this.kind == OperationKind.Action) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters"); } if (this.resultSetPathExpression != null) { this.resultSetPathExpression.SetBindingParameter(this.bindingParameter); } } }
/// <summary> /// Initializes a new <see cref="Operation"/> instance. /// </summary> /// <param name="name">name of the operation.</param> /// <param name="resultKind">Kind of result expected from this operation.</param> /// <param name="returnType">Return type of the operation.</param> /// <param name="resultSet">EntitySet of the result expected from this operation, must be null if <paramref name="resultSetPathExpression"/> is not null.</param> /// <param name="resultSetPathExpression">Path expression to calculate the result set of the operation, must be null if <paramref name="resultSet"/> is not null.</param> /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param> /// <param name="parameters">In-order parameters for this operation.</param> /// <param name="operationParameterBindingKind">the kind of the operation parameter binding (Never, Sometimes, Always).</param> /// <param name="kind">The kind of the current service operation.</param> internal Operation( string name, ServiceOperationResultKind resultKind, ResourceType returnType, ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable <OperationParameter> parameters, OperationParameterBindingKind operationParameterBindingKind, OperationKind kind) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNullOrEmpty(method, "method"); Debug.Assert( this.GetType() == typeof(ServiceOperation) && kind == OperationKind.ServiceOperation || this.GetType() == typeof(ServiceAction) && kind == OperationKind.Action, "OperationKind and the current type doesn't match."); ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind); this.name = name; this.resultKind = resultKind; this.returnType = returnType; this.resourceSet = resultSet; this.resultSetPathExpression = resultSetPathExpression; this.method = method; this.kind = kind; this.operationParameterBindingKind = operationParameterBindingKind; this.operationParameters = Operation.ValidateParameters(this.operationParameterBindingKind, parameters); if (this.operationParameterBindingKind != OperationParameterBindingKind.Never) { Debug.Assert( this.operationParameterBindingKind == OperationParameterBindingKind.Always || this.operationParameterBindingKind == OperationParameterBindingKind.Sometimes, "Value of operationParameterBindingKind was expected to be 'always' or 'sometimes'."); Debug.Assert(this.kind != OperationKind.ServiceOperation, "ServiceOperations should never be bindable."); this.bindingParameter = this.operationParameters.FirstOrDefault(); if (this.bindingParameter == null) { throw new ArgumentException(Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind"); } if (resourceSet != null) { throw new ArgumentException(Strings.Opereration_BoundOperationsMustNotSpecifyEntitySetOnlyEntitySetPath(this.name), "resourceSet"); } if (resultSetPathExpression != null && this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType && this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection) { throw new ArgumentException(Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression")); } if (this.kind == OperationKind.Action && !(this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityType || this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityCollection)) { throw new ArgumentException(Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters"); } if (this.resultSetPathExpression != null) { this.resultSetPathExpression.SetBindingParameter(this.bindingParameter); } } Debug.Assert(this.kind != OperationKind.Action || string.CompareOrdinal(XmlConstants.HttpMethodPost, this.method) == 0, "HttpMethod must be POST for Actions."); Debug.Assert(this.resourceSet == null || this.resultSetPathExpression == null, "'resultSet' and 'resultSetPathExpression' cannot be both set by the constructor."); }