Configure SSL Binding for RESTful WCF. How?

My current configuration looks like this:

<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> 

This works when I have the http and https bindings configured for my site.

I connect to the service via https and everything works fine.

Now I want to completely remove the http binding for IIS. And I started getting this error:

Could not find a base address that matches the http scheme for the endpoint with WebHttpBinding. Schemes of registered base addresses [https].

[InvalidOperationException: Could not find a base address that matches the http scheme for the endpoint with WebHttpBinding. registered base address patterns [https].]
System.ServiceModel.ServiceHostBase.MakeAbsoluteUri (Uri relativeOrAbsoluteUri, Binding Binding, UriSchemeKeyedCollection baseAddresses) +16582113
System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress (ServiceEndpointElement serviceEndpointElement, host ServiceHostBase, ServiceEndpoint endpoint) +117
System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint (StandardEndpointElement standardEndpointElement, ServiceEndpointElement serviceEndpointElement, context information context, ServiceHostBase host, ServiceDescription description, ServiceEndpoint & endpoint, Boolean omitSettingEndpointdress)
System.ServiceModel.Description.ConfigLoader.LookupEndpoint (ServiceEndpointElement serviceEndpointElement, context information context, ServiceHostBase host, ServiceDescription description, Boolean omitSettingEndpointAddress) +8728167
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints (ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String standardEndpointKind) +982
System.ServiceModel.Web.WebServiceHost.OnOpening () +311
System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) +612
System.ServiceModel.HostingManager.ActivateService (String normalizedVirtualPath) +255
System.ServiceModel.HostingManager.EnsureServiceAvailable (String normalizedVirtualPath) +1172

[ServiceActivationException: service / DEMO / mobile cannot be activated due to an exception at compile time. Exception message: Could not find a base address that matches the http scheme for the endpoint with WebHttpBinding. Registered base address of the scheme [https] ..] System.Runtime.AsyncResult.End (IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End (IAsyncResult result) +178702
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion (IAsyncResult ar) +136

I found a sample set for WCF, but WCF REST looks different on the configuration side, and I want to understand why it compiles. From the look of my configuration - it should not work on SSL at all, but it works when there is an https binding.

+4
source share
3 answers

Do what the error says ... fix the binding

  <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> 
+3
source

The accepted answer did not work for me because I needed to save my standard endpoint element. I managed to remove the http binding and only leave the https binding in IIS by adding the <webHttpBinding> section to my Web.config

Be sure not to set the name property to <binding> , otherwise it will not work

The relevant part of my Web.config is:

  <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> 
+1
source

try it

 <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> 
0
source

Source: https://habr.com/ru/post/1399568/


All Articles