为RESTful WCF配置SSL绑定.怎样
本文关键字:绑定 怎样 SSL 配置 RESTful WCF | 更新日期: 2023-09-27 18:26:29
我当前的配置看起来是这样的:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<!--Set limit to 5 megabytes-->
<standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="5242880">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
当我为我的网站配置了http
和https
绑定时,这就可以工作了。
我通过https连接到服务,一切都很好。
现在我想完全删除IIS上的http
绑定。我开始犯这样的错误:
找不到与的方案http匹配的基地址具有绑定WebHttpBinding的终结点。已注册的基本地址方案是[https]。
InvalidOperationException:找不到匹配的基地址为具有绑定WebHttpBinding的端点配置http。已注册基本地址方案是[https].]
System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(UrirelativeOrAbsoluteUri,绑定,UriSchemeKeyedCollectionbaseAddresses)+16582113
System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElementserviceEndpointElement,ServiceHostBase主机,ServiceEndpoint端点)+117
System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement标准端点元素,服务端点元素serviceEndpointElement,ContextInformation上下文,ServiceHostBase主机,ServiceDescription描述,ServiceEndpoint&端点,布尔值省略SettingEndpointAddress)+937
System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElementserviceEndpointElement,ContextInformation上下文,ServiceHostBase主机,ServiceDescription描述,布尔值omitSettingEndpointAddress)+8728167
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHosthost,IDictionary `2 implementedContracts,StringmultipleContractsErrorMessage,字符串标准EndpointKind)+982
System.ServiceModel.Web.WebServiceHost.OnOpen()+311
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+612
System.ServiceModel.HostingManager.ActivateService(字符串normalizedVirtualPath)+255
System.ServiceModel.HostingManager.EnsureServiceAvailable(字符串normalizedVirtualPath)+1172[ServiceActivationException:服务"/DEMO/mobile"不能由于编译期间出现异常而激活。例外情况消息为:找不到与的方案http匹配的基地址具有绑定WebHttpBinding的端点。注册的基本地址方案是[https]..]System.Runtime.AsyncResult.End(IAsyncResult结果)+90424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult结果)+178702
System.Web.CallHandlerExecutionStep.OnAsyncHandlerComplete(IAsyncResultar)+136
我发现了一堆WCF的示例,但REST WCF在配置方面看起来有所不同,我想了解为什么它是兼容的。从我的配置来看,它根本不应该在SSL上工作,但当存在https绑定时,它确实工作。。
按照错误指示执行。。。修复绑定
<services>
<service name="service" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="https"
contract="IContract" behaviorConfiguration="endpointBehavior">
</endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="https" maxReceivedMessageSize="65536">
<security mode="Transport" />
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
接受的答案对我不起作用,因为我需要保留我的标准端点元素。通过在Web.config 中添加<webHttpBinding>
部分,我可以删除http绑定,只在IIS中保留https绑定
请确保不要在<binding>
上设置name
属性,否则这将不起作用
我的Web.config的相关部分:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
<webHttpBinding>
<binding>
<!-- Comment out the following line if HTTP is used. If HTTPS is used, leave it enabled -->
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="false" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
试试这个
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<!--Set limit to 5 megabytes-->
<standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="5242880">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</standardEndpoint>
<security mode="Transport" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>