コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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}\".");
                }
            }
        }
コード例 #3
0
        public void Activate([NotNull] IRouteBuilder routeBuilder)
        {
            if (routeBuilder == null)
            {
                throw new ArgumentNullException(nameof(routeBuilder));
            }

            foreach (var service in mServices.Values)
            {
                var exporter = new WebServiceExporter(service, this);

                exporter.RoutePrefix = Configuration.RoutePrefix;
                exporter.Log         = Log;

                foreach (var routeInfo in exporter.Export(routeBuilder))
                {
                    RouteMapped?.Invoke(this, routeInfo);
                }
            }

            mWasActivated = true;
        }
コード例 #4
0
        public void Configure(IApplicationBuilder applicationBuilder, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory)
        {
            var routeBuilder = new RouteBuilder(applicationBuilder);

            foreach (var service in mProvider.Services)
            {
                var exporter = new WebServiceExporter(service, mProvider);

                exporter.RoutePrefix = mProvider.Configuration.Configuration.RoutePrefix.NormalizeNull();
                exporter.Log         = mProvider.Log;

                foreach (var routeInfo in exporter.Export(routeBuilder))
                {
                    mProvider.RaiseRouteMappedEvent(routeInfo);
                }
            }

            loggerFactory.AddProvider(new ServiceLogProvider(mProvider.Log, mProvider.Configuration.LogMessageScope));

            applicationBuilder.UseRouter(routeBuilder.Build());
            applicationBuilder.UseStatusCodePages(HandleFaultStatusCode);
        }