从 http 到 https,得到 "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding"
Going from http to https, getting "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding"
我遇到了一个问题:
下面的配置过去工作正常(站点的绑定是 http,端口 81)。在站点的绑定更改为 https、端口 443 并使用有效的服务器身份验证证书后,它现在失败了。事件查看器中的错误消息是这样的:
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/25652103
Exception: System.ServiceModel.ServiceActivationException: The service '/services/api/oauth2' cannot be activated due to an exception during compilation. The exception message is: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].. ---> System.InvalidOperationException: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].
at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement serviceEndpointElement, ServiceHostBase host, ServiceEndpoint endpoint)
at System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement standardEndpointElement, ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, ServiceEndpoint& endpoint, Boolean omitSettingEndpointAddress)
at System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, Boolean omitSettingEndpointAddress)
at System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String noContractErrorMessage, String standardEndpointKind)
at System.ServiceModel.Web.WebServiceHost.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
--- End of inner exception stack trace ---
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
Process Name: w3wp
web.config 对于“api”应用程序:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="tinCanBinding" closeTimeout="00:01:00">
</binding>
</webHttpBinding>
</bindings>
<extensions>
<behaviorExtensions>
<add name="tinCanWebHttp" type="Company.RestService.TinCan.RestConfiguration.TinCanWebHttpBehaviorExtension, Company.RestService" />
<add name="ErrorHandler" type="Company.RestService.ApiErrorHandlerBehavior, Company.RestService" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<ErrorHandler />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="tinCanBehavior">
<tinCanWebHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Company.RestService.TinCan.TinCanService">
<endpoint address="" behaviorConfiguration="tinCanBehavior" bindingConfiguration="tinCanBinding" binding="webHttpBinding" contract="Company.RestService.ServiceContracts.TinCan.ITinCanService">
</endpoint>
</service>
<service name="Company.RestService.CallBackRestService">
<endpoint address="" binding="wsDualHttpBinding" contract="Company.RestService.ICallBackService">
</endpoint>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false">
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="DSPExceptionModule" />
<remove name="DSPThrottleModule" />
<remove name="DSPTraceModule" />
<remove name="DSPAuthenticationModule" />
<add type="Company.ServiceHttpModule.DSPExceptionModule,Company.ServiceHttpModule" name="DSPExceptionModule" />
<add type="Company.ServiceHttpModule.DSPThrottleModule,Company.ServiceHttpModule" name="DSPThrottleModule" />
<add type="Company.ServiceHttpModule.DSPTraceModule,Company.ServiceHttpModule" name="DSPTraceModule" />
<add type="Company.ServiceHttpModule.DSPAuthenticationModule,Company.ServiceHttpModule" name="DSPAuthenticationModule" />
</modules>
</system.webServer>
<system.web>
<compilation debug="true" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="3.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
看起来它希望“oauth2”本身是一个应用程序,它有自己的 web.config,而它只是路由的一部分,应该在“api”中处理。上面的 web.config 需要更改什么才能使其正常工作?
如果要使用https,请参考以下配置:
<system.serviceModel >
<services>
<service name="WcfService30.Service1"
behaviorConfiguration="ServiceBehaviour" >
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="webHttpTransportSecurity"
behaviorConfiguration="web"
contract="WcfService30.IService1" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpsGetEnabled="true"
httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
要使用https,您需要将安全模式设置为传输。
更新:
绑定截图:
我遇到了一个问题:
下面的配置过去工作正常(站点的绑定是 http,端口 81)。在站点的绑定更改为 https、端口 443 并使用有效的服务器身份验证证书后,它现在失败了。事件查看器中的错误消息是这样的:
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/25652103
Exception: System.ServiceModel.ServiceActivationException: The service '/services/api/oauth2' cannot be activated due to an exception during compilation. The exception message is: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].. ---> System.InvalidOperationException: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].
at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement serviceEndpointElement, ServiceHostBase host, ServiceEndpoint endpoint)
at System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement standardEndpointElement, ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, ServiceEndpoint& endpoint, Boolean omitSettingEndpointAddress)
at System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, Boolean omitSettingEndpointAddress)
at System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String noContractErrorMessage, String standardEndpointKind)
at System.ServiceModel.Web.WebServiceHost.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
--- End of inner exception stack trace ---
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
Process Name: w3wp
web.config 对于“api”应用程序:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="tinCanBinding" closeTimeout="00:01:00">
</binding>
</webHttpBinding>
</bindings>
<extensions>
<behaviorExtensions>
<add name="tinCanWebHttp" type="Company.RestService.TinCan.RestConfiguration.TinCanWebHttpBehaviorExtension, Company.RestService" />
<add name="ErrorHandler" type="Company.RestService.ApiErrorHandlerBehavior, Company.RestService" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<ErrorHandler />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="tinCanBehavior">
<tinCanWebHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Company.RestService.TinCan.TinCanService">
<endpoint address="" behaviorConfiguration="tinCanBehavior" bindingConfiguration="tinCanBinding" binding="webHttpBinding" contract="Company.RestService.ServiceContracts.TinCan.ITinCanService">
</endpoint>
</service>
<service name="Company.RestService.CallBackRestService">
<endpoint address="" binding="wsDualHttpBinding" contract="Company.RestService.ICallBackService">
</endpoint>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false">
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="DSPExceptionModule" />
<remove name="DSPThrottleModule" />
<remove name="DSPTraceModule" />
<remove name="DSPAuthenticationModule" />
<add type="Company.ServiceHttpModule.DSPExceptionModule,Company.ServiceHttpModule" name="DSPExceptionModule" />
<add type="Company.ServiceHttpModule.DSPThrottleModule,Company.ServiceHttpModule" name="DSPThrottleModule" />
<add type="Company.ServiceHttpModule.DSPTraceModule,Company.ServiceHttpModule" name="DSPTraceModule" />
<add type="Company.ServiceHttpModule.DSPAuthenticationModule,Company.ServiceHttpModule" name="DSPAuthenticationModule" />
</modules>
</system.webServer>
<system.web>
<compilation debug="true" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="3.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
看起来它希望“oauth2”本身是一个应用程序,它有自己的 web.config,而它只是路由的一部分,应该在“api”中处理。上面的 web.config 需要更改什么才能使其正常工作?
如果要使用https,请参考以下配置:
<system.serviceModel >
<services>
<service name="WcfService30.Service1"
behaviorConfiguration="ServiceBehaviour" >
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="webHttpTransportSecurity"
behaviorConfiguration="web"
contract="WcfService30.IService1" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpsGetEnabled="true"
httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
要使用https,您需要将安全模式设置为传输。
更新:
绑定截图: