c# - The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

ID : 10188

viewed : 39

Tags : c#wcfhttpsc#

Top 5 Answer for c# - The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

vote vote

96

Try adding message credentials on your app.config like:

<bindings>  <basicHttpBinding>  <binding name="defaultBasicHttpBinding">    <security mode="Transport">      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>      <message clientCredentialType="Certificate" algorithmSuite="Default" />   </security>  </binding>  </basicHttpBinding>  </bindings>  
vote vote

88

Adding this as an answer, just since you can't do much fancy formatting in comments.
I had the same issue, except I was creating and binding my web service client entirely in code.
Reason is the DLL was being uploaded into a system, which prohibited the use of config files.

Here is the code as it needed to be updated to communicate over SSL...

Public Function GetWebserviceClient() As WebWorker.workerSoapClient     Dim binding = New BasicHttpBinding()     binding.Name = "WebWorkerSoap"     binding.CloseTimeout = TimeSpan.FromMinutes(1)     binding.OpenTimeout = TimeSpan.FromMinutes(1)     binding.ReceiveTimeout = TimeSpan.FromMinutes(10)     binding.SendTimeout = TimeSpan.FromMinutes(1)      '// HERE'S THE IMPORTANT BIT FOR SSL     binding.Security.Mode = BasicHttpSecurityMode.Transport      Dim endpoint = New EndpointAddress("https://myurl/worker.asmx")      Return New WebWorker.workerSoapClient(binding, endpoint) End Function 
vote vote

76

Change from

<security mode="None"> 

to

<security mode="Transport"> 

in your web.config file. This change will allow you to use https instead of http

vote vote

65

Are you running this on the Cassini (vs dev server) or on IIS with a cert installed? I have had issues in the past trying to hook up secure endpoints on the dev web server.

Here is the binding configuration that has worked for me in the past. Instead of basicHttpBinding, it uses wsHttpBinding. I don't know if that is a problem for you.

<!-- Binding settings for HTTPS endpoint --> <binding name="WsSecured">     <security mode="Transport">         <transport clientCredentialType="None" />         <message clientCredentialType="None"             negotiateServiceCredential="false"             establishSecurityContext="false" />     </security> </binding> 

and the endpoint

<endpoint address="..." binding="wsHttpBinding"     bindingConfiguration="WsSecured" contract="IYourContract" /> 

Also, make sure you change the client configuration to enable Transport security.

vote vote

51

I had same exception in a custom binding scenario. Anybody using this approach, can check this too.

I was actually adding the service reference from a local WSDL file. It got added successfully and required custom binding was added to config file. However, the actual service was https; not http. So I changed the httpTransport elemet as httpsTransport. This fixed the problem

<system.serviceModel> <bindings>    <customBinding>     <binding name="MyBindingConfig">        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"         messageVersion="Soap11" writeEncoding="utf-8">         <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"           maxBytesPerRead="4096" maxNameTableCharCount="16384" />       </textMessageEncoding>        <!--Manually changed httpTransport to httpsTransport-->       <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"         maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"         bypassProxyOnLocal="false"          decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"         keepAliveEnabled="true" maxBufferSize="65536"          proxyAuthenticationScheme="Anonymous"         realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"         useDefaultWebProxy="true" />     </binding>   </customBinding>  </bindings>  <client>   <endpoint address="https://mainservices-certint.mycompany.com/Services/HRTest"     binding="customBinding" bindingConfiguration="MyBindingConfig"     contract="HRTest.TestWebserviceManagerImpl" name="TestWebserviceManagerImpl" /> </client>   </system.serviceModel> 

References

  1. WCF with custombinding on both http and https

Top 3 video Explaining c# - The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

Related QUESTION?