我尝试从其他问题中实施一些建议来解决这个令人沮丧的问题。通常,当我在IIS中设置站点时,Web应用程序与传输层的内容有些“不可知”。但是,对于这个特定的应用程序,当我应用https绑定时,我无法使其工作。
我的web.config看起来像:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="DefaultAPIBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
和我的Global.asax.cs看起来像
ContainerBuilder builder = new ContainerBuilder();
//builder.Register<IContactRepository, ContactRepository>();
builder.Register<IResourceFactory, Classes.LightCoreResourceFactory>();
IContainer container = builder.Build();
var configuration = HttpHostConfiguration.Create().SetResourceFactory(new LightCoreResourceFactory(container));
RouteTable.Routes.MapServiceRoute<WebServiceResources>("ws", configuration);
但每当我向我的IIS站点添加https
绑定时,我都会收到错误:
The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: context.ListenUriBaseAddress
[ArgumentException: The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: context.ListenUriBaseAddress]
System.ServiceModel.Channels.TransportChannelListener..ctor(TransportBindingElement bindingElement, BindingContext context, MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode) +12800194
System.ServiceModel.Channels.HttpChannelListener..ctor(HttpTransportBindingElement bindingElement, BindingContext context) +41
System.ServiceModel.Channels.HttpChannelListener`1..ctor(HttpTransportBindingElement bindingElement, BindingContext context) +28
System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener(BindingContext context) +133
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
Microsoft.ApplicationServer.Http.Channels.HttpMessageEncodingBindingElement.BuildChannelListener(BindingContext context) +90
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
Microsoft.ApplicationServer.Http.Channels.HttpMessageHandlerBindingElement.BuildChannelListener(BindingContext context) +158
System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener() +63
System.ServiceModel.Channels.Binding.BuildChannelListener(Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) +125
System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession) +336
System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +716
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +1131
System.ServiceModel.ServiceHostBase.InitializeRuntime() +65
System.ServiceModel.ServiceHostBase.OnBeginOpen() +34
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +310
System.ServiceModel.Channels.CommunicationObject.Open() +36
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +91
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
[ServiceActivationException: The service '/ws' cannot be activated due to an exception during compilation. The exception message is: The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: context.ListenUriBaseAddress.]
System.Runtime.AsyncResult.End(IAsyncResult result) +495736
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178
System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
由于错误消息未在我的代码中提供检查位置或任何其他提示,并且因为我已经实现了一些关于如何解决此问题的其他建议,所以我感到很茫然。知道如何使这个应用程序允许https
绑定?
答案 0 :(得分:1)
详细说明@thedr所说的,这就是我们所做的:
public class HttpsServiceHostFactory : HttpConfigurableServiceHostFactory { public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) { var host = base.CreateServiceHost(constructorString, baseAddresses); foreach (var httpBinding in from serviceEndpoint in host.Description.Endpoints where serviceEndpoint.ListenUri.Scheme == "https" select (HttpBinding)serviceEndpoint.Binding) { httpBinding.Security.Mode = HttpBindingSecurityMode.Transport; } return host; } }
然后当你RouteTable.Routes.MapServiceRoute
时,它应该看起来像
RouteTable.Routes. MapServiceRoute<WebServiceResources, HttpsServiceHostFactory>("ws", configuration);