Custom binding: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

Kiddo picture Kiddo · Jul 19, 2012 · Viewed 8.4k times · Source

I have looked all over stackoverflow and internet, still can't find a solution for this I have set up a custom basichttpbinding with a 'https' endpoint. when I call the method, it kept return me exception:

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

var endPoint = new EndpointAddress("https://xxxxx/v2_soap/index/");

var binding = new BasicHttpBinding
{
    Name = "HandlerBinding",
        CloseTimeout = TimeSpan.FromMinutes(1.0),
        HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
        MessageEncoding = WSMessageEncoding.Text,
        MaxReceivedMessageSize = 65536000,
        MaxBufferPoolSize = 65536000,
        UseDefaultWebProxy = true,
        AllowCookies = false,
        BypassProxyOnLocal = false,
        Security =
    {
        Mode =BasicHttpSecurityMode.Transport,
        Transport =
        {
            ClientCredentialType = HttpClientCredentialType.None,
            ProxyCredentialType = HttpProxyCredentialType.None
        },
        Message =
            {
                ClientCredentialType = BasicHttpMessageCredentialType.UserName
            }
    } 
};

the above settings are exact the same as the app.config the VS generated when adding a service reference:

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HandlerBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://xxxxx/v2_soap/index/?SID=qttkobaa5jrmaj22il8mn9n342"
        binding="basicHttpBinding" bindingConfiguration="HandlerBinding"
        contract="HandlerPortType"
        name="HandlerPort" />
    </client>
  </system.serviceModel>

I even tried to change from basichttpbinding to WSHttpBinding, and still no luck.

Answer

Alexander Efimov picture Alexander Efimov · Jul 19, 2012

There is a good article on CodeProject for this: SSL for self hosted WCF service