3

我最近将 HTTPS 添加到我的 WCF 服务中,该服务在我的开发 IIS 服务器上正常工作,适用于 HTTP 和 HTTPS。但是,现在当我尝试使用 Visual Studio (localhost) 运行时,在尝试访问服务时出现此错误:

Exception: System.InvalidOperationException
Description: Could not find a base address that matches scheme https for the endpoint    with binding WebHttpBinding. Registered base address schemes are [http]. 
Timestamp: 5/15/2013 4:23:04 PM
Client IP Address/DNS Name: ::1 - ::1

at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri,    Binding binding, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost)

这是我的 web.config:

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="sslBinding">
        <security mode="Transport">
          <transport clientCredentialType="None" proxyCredentialType="None" />
        </security>
      </binding>
    </webHttpBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="ServiceBehavior" name="HistoryService">
      <endpoint behaviorConfiguration="webHttp" binding="webHttpBinding" contract="IHistoryService" />
      <endpoint binding="webHttpBinding" contract="IHistoryService" behaviorConfiguration="webHttp" bindingConfiguration="sslBinding" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttp">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

如果我可以继续使用 Visual Studio 的开发服务器进行开发,那就太好了。我需要为 Visual Studio 开发服务器启用什么功能才能使用 HTTPS 吗?或者我可以在我的 web.config 中修改一些东西以使其正常运行?

4

1 回答 1

8

Visual Studio 中的内置 Web 服务器不支持 SSL。这是一个关于使用 IIS Express 的不错的教程。我使用 Microsoft WebMatrix,这使得使用 IIS Express 设置站点变得简单。

http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

于 2013-05-16T02:43:55.633 回答