| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Collections.Generic; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | using CoreWCF.OpenApi; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | using Swashbuckle.AspNetCore.Swagger; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Configuration |
| | | 12 | | { |
| | | 13 | | public static class ServiceModelWebServiceBuilderExtensions |
| | | 14 | | { |
| | | 15 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 16 | | this IServiceBuilder builder, |
| | | 17 | | string address, |
| | 30 | 18 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 30 | 19 | | builder, |
| | 30 | 20 | | typeof(TContract), |
| | 30 | 21 | | address, |
| | 30 | 22 | | configureWebBehavior); |
| | | 23 | | |
| | | 24 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 25 | | this IServiceBuilder builder, |
| | | 26 | | WebHttpBinding binding, |
| | | 27 | | string address, |
| | 7 | 28 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 7 | 29 | | builder, |
| | 7 | 30 | | typeof(TContract), |
| | 7 | 31 | | binding, |
| | 7 | 32 | | address, |
| | 7 | 33 | | configureWebBehavior); |
| | | 34 | | |
| | | 35 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 36 | | this IServiceBuilder builder, |
| | | 37 | | Uri address, |
| | 0 | 38 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 39 | | builder, |
| | 0 | 40 | | typeof(TContract), |
| | 0 | 41 | | address, |
| | 0 | 42 | | configureWebBehavior); |
| | | 43 | | |
| | | 44 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 45 | | this IServiceBuilder builder, |
| | | 46 | | WebHttpBinding binding, |
| | | 47 | | Uri address, |
| | 0 | 48 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 49 | | builder, |
| | 0 | 50 | | typeof(TContract), |
| | 0 | 51 | | binding, |
| | 0 | 52 | | address, |
| | 0 | 53 | | configureWebBehavior); |
| | | 54 | | |
| | | 55 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 56 | | this IServiceBuilder builder, |
| | | 57 | | string address, |
| | | 58 | | Uri listenUri, |
| | 0 | 59 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 60 | | builder, |
| | 0 | 61 | | typeof(TContract), |
| | 0 | 62 | | address, |
| | 0 | 63 | | listenUri, |
| | 0 | 64 | | configureWebBehavior); |
| | | 65 | | |
| | | 66 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 67 | | this IServiceBuilder builder, |
| | | 68 | | WebHttpBinding binding, |
| | | 69 | | string address, |
| | | 70 | | Uri listenUri, |
| | 0 | 71 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 72 | | builder, |
| | 0 | 73 | | typeof(TContract), |
| | 0 | 74 | | binding, |
| | 0 | 75 | | address, |
| | 0 | 76 | | listenUri, |
| | 0 | 77 | | configureWebBehavior); |
| | | 78 | | |
| | | 79 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 80 | | this IServiceBuilder builder, |
| | | 81 | | Uri address, |
| | | 82 | | Uri listenUri, |
| | 0 | 83 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 84 | | builder, |
| | 0 | 85 | | typeof(TContract), |
| | 0 | 86 | | address, |
| | 0 | 87 | | listenUri, |
| | 0 | 88 | | configureWebBehavior); |
| | | 89 | | |
| | | 90 | | public static IServiceBuilder AddServiceWebEndpoint<TService, TContract>( |
| | | 91 | | this IServiceBuilder builder, |
| | | 92 | | WebHttpBinding binding, |
| | | 93 | | Uri address, |
| | | 94 | | Uri listenUri, |
| | 0 | 95 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 96 | | builder, |
| | 0 | 97 | | typeof(TContract), |
| | 0 | 98 | | binding, |
| | 0 | 99 | | address, |
| | 0 | 100 | | listenUri, |
| | 0 | 101 | | configureWebBehavior); |
| | | 102 | | |
| | | 103 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 104 | | this IServiceBuilder builder, |
| | | 105 | | Type implementedContract, |
| | | 106 | | string address, |
| | 30 | 107 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 30 | 108 | | builder, |
| | 30 | 109 | | implementedContract, |
| | 30 | 110 | | address, |
| | 30 | 111 | | (Uri)null, |
| | 30 | 112 | | configureWebBehavior); |
| | | 113 | | |
| | | 114 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 115 | | this IServiceBuilder builder, |
| | | 116 | | Type implementedContract, |
| | | 117 | | WebHttpBinding binding, |
| | | 118 | | string address, |
| | 7 | 119 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 7 | 120 | | builder, |
| | 7 | 121 | | implementedContract, |
| | 7 | 122 | | binding, |
| | 7 | 123 | | address, |
| | 7 | 124 | | (Uri)null, |
| | 7 | 125 | | configureWebBehavior); |
| | | 126 | | |
| | | 127 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 128 | | this IServiceBuilder builder, |
| | | 129 | | Type implementedContract, |
| | | 130 | | Uri address, |
| | 0 | 131 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 132 | | builder, |
| | 0 | 133 | | implementedContract, |
| | 0 | 134 | | address, |
| | 0 | 135 | | (Uri)null, |
| | 0 | 136 | | configureWebBehavior); |
| | | 137 | | |
| | | 138 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 139 | | this IServiceBuilder builder, |
| | | 140 | | Type implementedContract, |
| | | 141 | | WebHttpBinding binding, |
| | | 142 | | Uri address, |
| | 0 | 143 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 0 | 144 | | builder, |
| | 0 | 145 | | implementedContract, |
| | 0 | 146 | | binding, |
| | 0 | 147 | | address, |
| | 0 | 148 | | (Uri)null, |
| | 0 | 149 | | configureWebBehavior); |
| | | 150 | | |
| | | 151 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 152 | | this IServiceBuilder builder, |
| | | 153 | | Type implementedContract, |
| | | 154 | | string address, |
| | | 155 | | Uri listenUri, |
| | 30 | 156 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 30 | 157 | | builder, |
| | 30 | 158 | | implementedContract, |
| | 30 | 159 | | new Uri(address, UriKind.RelativeOrAbsolute), |
| | 30 | 160 | | listenUri, |
| | 30 | 161 | | configureWebBehavior); |
| | | 162 | | |
| | | 163 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 164 | | this IServiceBuilder builder, |
| | | 165 | | Type implementedContract, |
| | | 166 | | WebHttpBinding binding, |
| | | 167 | | string address, |
| | | 168 | | Uri listenUri, |
| | 7 | 169 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint<TService>( |
| | 7 | 170 | | builder, |
| | 7 | 171 | | implementedContract, |
| | 7 | 172 | | binding, |
| | 7 | 173 | | new Uri(address, UriKind.RelativeOrAbsolute), |
| | 7 | 174 | | listenUri, |
| | 7 | 175 | | configureWebBehavior); |
| | | 176 | | |
| | | 177 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 178 | | this IServiceBuilder builder, |
| | | 179 | | Type implementedContract, |
| | | 180 | | Uri address, |
| | | 181 | | Uri listenUri, |
| | 30 | 182 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint( |
| | 30 | 183 | | builder, |
| | 30 | 184 | | typeof(TService), |
| | 30 | 185 | | implementedContract, |
| | 30 | 186 | | new WebHttpBinding(), |
| | 30 | 187 | | address, |
| | 30 | 188 | | listenUri, |
| | 30 | 189 | | configureWebBehavior); |
| | | 190 | | |
| | | 191 | | public static IServiceBuilder AddServiceWebEndpoint<TService>( |
| | | 192 | | this IServiceBuilder builder, |
| | | 193 | | Type implementedContract, |
| | | 194 | | WebHttpBinding binding, |
| | | 195 | | Uri address, |
| | | 196 | | Uri listenUri, |
| | 7 | 197 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint( |
| | 7 | 198 | | builder, |
| | 7 | 199 | | typeof(TService), |
| | 7 | 200 | | implementedContract, |
| | 7 | 201 | | binding, |
| | 7 | 202 | | address, |
| | 7 | 203 | | listenUri, |
| | 7 | 204 | | configureWebBehavior); |
| | | 205 | | |
| | | 206 | | public static IServiceBuilder AddServiceWebEndpoint( |
| | | 207 | | this IServiceBuilder builder, |
| | | 208 | | Type service, |
| | | 209 | | Type implementedContract, |
| | | 210 | | Uri address, |
| | | 211 | | Uri listenUri, |
| | 0 | 212 | | Action<WebHttpBehavior> configureWebBehavior = null) => AddServiceWebEndpoint( |
| | 0 | 213 | | builder, |
| | 0 | 214 | | service, |
| | 0 | 215 | | implementedContract, |
| | 0 | 216 | | new WebHttpBinding(), |
| | 0 | 217 | | address, |
| | 0 | 218 | | listenUri, |
| | 0 | 219 | | configureWebBehavior); |
| | | 220 | | |
| | | 221 | | public static IServiceBuilder AddServiceWebEndpoint( |
| | | 222 | | this IServiceBuilder builder, |
| | | 223 | | Type service, |
| | | 224 | | Type implementedContract, |
| | | 225 | | WebHttpBinding binding, |
| | | 226 | | Uri address, |
| | | 227 | | Uri listenUri, |
| | | 228 | | Action<WebHttpBehavior> configureWebBehavior = null) |
| | | 229 | | { |
| | 37 | 230 | | builder.AddServiceEndpoint(service, implementedContract, binding, address, listenUri, serviceEndpoint => |
| | 37 | 231 | | { |
| | 37 | 232 | | KeyedByTypeCollection<IEndpointBehavior> behaviors = (KeyedByTypeCollection<IEndpointBehavior>)serviceEn |
| | 37 | 233 | | WebHttpBehavior webHttpBehavior = behaviors.Find<WebHttpBehavior>() ?? throw DiagnosticUtility.Exception |
| | 37 | 234 | | configureWebBehavior?.Invoke(webHttpBehavior); |
| | 37 | 235 | | |
| | 37 | 236 | | if (webHttpBehavior.HelpEnabled) |
| | 37 | 237 | | { |
| | 0 | 238 | | OpenApiDocumentProvider documentProvider = webHttpBehavior.ServiceProvider.GetRequiredService<OpenAp |
| | 0 | 239 | | documentProvider.Contracts.Add(new OpenApiContractInfo |
| | 0 | 240 | | { |
| | 0 | 241 | | Contract = implementedContract, |
| | 0 | 242 | | ResponseFormat = webHttpBehavior.DefaultOutgoingResponseFormat |
| | 0 | 243 | | }); |
| | 37 | 244 | | } |
| | 74 | 245 | | }); |
| | | 246 | | |
| | 37 | 247 | | return builder; |
| | | 248 | | } |
| | | 249 | | } |
| | | 250 | | } |