|
7 | 7 | using System.Net;
|
8 | 8 | using System.Security.Claims;
|
9 | 9 | using System.Security.Cryptography.X509Certificates;
|
| 10 | +using CoreWCF.Channels; |
10 | 11 | using CoreWCF.Configuration;
|
11 | 12 | using CoreWCF.Description;
|
12 | 13 | using idunno.Authentication.Basic;
|
@@ -41,17 +42,11 @@ internal static IDictionary<ServiceSchema, string> BaseAddresses
|
41 | 42 | dict[ServiceSchema.HTTPS] = string.Format(@"https://localhost:{0}", httpsPort);
|
42 | 43 | var tcpPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("tcpPort")) ? DefaultTcpPort : int.Parse(Environment.GetEnvironmentVariable("tcpPort"));
|
43 | 44 | dict[ServiceSchema.NETTCP] = string.Format(@"net.tcp://localhost:{0}", tcpPort);
|
44 |
| -#if NET |
45 |
| - var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort")); |
46 |
| - dict[ServiceSchema.WS] = string.Format(@"ws://localhost:{0}", websocketPort); |
47 |
| - var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort")); |
48 |
| - dict[ServiceSchema.WSS] = string.Format(@"wss://localhost:{0}", websocketsPort); |
49 |
| -#else |
50 | 45 | var websocketPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketPort")) ? DefaultWebSocketPort : int.Parse(Environment.GetEnvironmentVariable("websocketPort"));
|
51 | 46 | dict[ServiceSchema.WS] = string.Format(@"http://localhost:{0}", websocketPort);
|
52 | 47 | var websocketsPort = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("websocketsPort")) ? DefaultWebSocketSPort : int.Parse(Environment.GetEnvironmentVariable("websocketsPort"));
|
53 | 48 | dict[ServiceSchema.WSS] = string.Format(@"https://localhost:{0}", websocketsPort);
|
54 |
| -#endif |
| 49 | + |
55 | 50 | s_baseAddresses = dict;
|
56 | 51 | dict[ServiceSchema.NETPIPE] = @"net.pipe://localhost";
|
57 | 52 | Console.WriteLine("Using base addresses:");
|
@@ -149,7 +144,7 @@ internal static async Task StartHosts()
|
149 | 144 | .Configure(app =>
|
150 | 145 | {
|
151 | 146 | app.UseAuthentication();
|
152 |
| - app.UseAuthorization(); |
| 147 | + app.UseAuthorization(); |
153 | 148 | app.UseServiceModel(serviceBuilder =>
|
154 | 149 | {
|
155 | 150 | foreach (var serviceTestHost in GetAttributedServiceHostTypes())
|
@@ -194,18 +189,26 @@ internal static async Task StartHosts()
|
194 | 189 | var serviceHost = (ServiceHost)Activator.CreateInstance(serviceTestHost, serviceTestHostOptionsDict[serviceHostTypeName].serviceBaseAddresses.ToArray());
|
195 | 190 | serviceBuilder.AddService(serviceHost.ServiceType, options =>
|
196 | 191 | {
|
197 |
| - var localHostTypeName = serviceHostTypeName; |
198 | 192 | options.BaseAddresses.Clear();
|
199 |
| - foreach (var baseAddress in BaseAddresses.Values) |
| 193 | + foreach (var baseAddress in BaseAddresses) |
200 | 194 | {
|
201 |
| - //if (!options.BaseAddresses.Contains(baseAddress)) |
202 |
| - options.BaseAddresses.Add(new Uri(baseAddress)); |
| 195 | + if ((BaseAddresses.ContainsKey(ServiceSchema.HTTP) && baseAddress.Key == ServiceSchema.WS) || |
| 196 | + (BaseAddresses.ContainsKey(ServiceSchema.HTTPS) && baseAddress.Key == ServiceSchema.WSS)) |
| 197 | + { |
| 198 | + continue; |
| 199 | + } |
| 200 | + |
| 201 | + options.BaseAddresses.Add(new Uri(baseAddress.Value)); |
203 | 202 | }
|
204 | 203 | });
|
205 | 204 |
|
206 | 205 | foreach (var endpoint in serviceHost.Endpoints)
|
207 | 206 | {
|
208 |
| - Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme); |
| 207 | + var customBinding = new CustomBinding(endpoint.Binding); |
| 208 | + var htbe = customBinding.Elements.Find<HttpTransportBindingElement>(); |
| 209 | + bool usesWebsockets = htbe != null && htbe.WebSocketSettings.TransportUsage == WebSocketTransportUsage.Always; |
| 210 | + |
| 211 | + Enum schema = ServiceHostHelper.ToServiceSchema(endpoint.Binding.Scheme, usesWebsockets); |
209 | 212 | string basePath = serviceTestHostOptionsDict[serviceHostTypeName].endpointBasePath[schema];
|
210 | 213 | string endpointAddress = string.Format("{0}/{1}", basePath, endpoint.Address);
|
211 | 214 | serviceBuilder.AddServiceEndpoint(serviceHost.ServiceType, endpoint.ContractType, endpoint.Binding, new Uri(endpointAddress, UriKind.RelativeOrAbsolute), null);
|
|
0 commit comments