public WebServiceOperation([NotNull] WebServiceExporter serviceExporter) { if (serviceExporter == null) { throw new ArgumentNullException(nameof(serviceExporter)); } mServiceExporter = serviceExporter; var type = mServiceExporter.GetExtensionType(); var method = type.GetMethod("Index", BindingFlags.Instance | BindingFlags.NonPublic) ?? type.GetMethod("Index", BindingFlags.Instance | BindingFlags.Public); if (method.GetParameters().Length == 0) { mMethod = method; mRoute = string.Empty; mVerbs = new[] { WebServiceVerbs.Get }; mParameters = new WebServiceOperationParameter[0]; } var authRequiredAttribute = method.GetCustomAttribute <RequireAuthenticationAttribute>(); if (authRequiredAttribute != null) { mAuthenticationRequired = true; mAuthenticationProviderType = authRequiredAttribute.ProviderType; } }
public WebServiceOperation([NotNull] WebServiceExporter serviceExporter, [NotNull] MethodBase method) { if (serviceExporter == null) { throw new ArgumentNullException(nameof(serviceExporter)); } if (method == null) { throw new ArgumentNullException(nameof(method)); } mServiceExporter = serviceExporter; var attribute = method.GetCustomAttribute <ServiceExport>(); if (attribute != null) { mMethod = method; mRoute = attribute.Route; mVerbs = Enum .GetValues(typeof(WebServiceVerbs)) .OfType <WebServiceVerbs>() .Except(new[] { WebServiceVerbs.All, WebServiceVerbs.None }) .Where(x => attribute.Verbs.HasFlag(x)) .ToArray(); mParameters = method.GetParameters().Select(x => new WebServiceOperationParameter(x)).ToArray(); var authRequiredAttribute = method.GetCustomAttribute <RequireAuthenticationAttribute>(); if (authRequiredAttribute != null) { mAuthenticationRequired = true; mAuthenticationProviderType = authRequiredAttribute.ProviderType; } if (mParameters.Count(x => x.FromBody) > 1) { throw new ArgumentException($"{mServiceExporter.GetExtensionType().FullName}.{method.Name}: only one parameter can be decorated with \"{typeof(FromBodyAttribute).Name}\"."); } } }