2013-09-25 2 views
0

Я попытался выполнить ряд предложений по другим вопросам, чтобы исправить эту неприятную проблему. Обычно, когда я настраивал сайт в IIS, веб-приложения несколько «агностичны» для того, что происходит на транспортном уровне. Однако для этого конкретного приложения я не могу заставить его работать, когда я применяю привязку https.Недопустимая схема URI UTR

Моя 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); 

Но всякий раз, когда я добавляю https связывание с моим сайтом IIS, я получаю ошибку :

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

но вы получаете стек? как насчет публикации этого. – shriek

+0

уверенная вещь ... хорошая точка –

+0

«Но всякий раз, когда я добавляю привязку https к моему сайту IIS, я получаю сообщение об ошибке:« можете ли вы пояснить, как добавить привязку https к вашему сайту IIS? Через сам IIS или? – Haney

ответ

1

Чтобы уточнить, что @thedr сказал, вот что мы сделали:

  1. Обновление до MVC4, если вы еще не сделали этого
  2. Добавьте следующий класс разорвал прямо из this CodePlex discussion
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); 
Смежные вопросы