Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via when i call IInternal proxy = factory.CreateChannel(); on Client

Tags:

c#

wcf

Server's App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehaviour">
          <serviceMetadata httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="Binding">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service name="Server.InternalClass" behaviorConfiguration="NewBehaviour">
        <endpoint address="IInternal" binding="wsHttpBinding" bindingConfiguration="Binding" contract="Common.IInternal">
          <identity>
            <dns value="MyMachine"/>
          </identity>
        </endpoint>
       <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
        <host>
          <baseAddresses>
            <add baseAddress="https://MyMachine:8733/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>


</configuration>

Client

static ChannelFactory<IInternal> factory = new ChannelFactory<IInternal>(new WSHttpBinding(), new EndpointAddress("https://MyMachine:8733/IInternal"));

When i call the method factory.CreateChannel(), i get error

I configure certificate

enter image description here

like image 318
user3661837 Avatar asked Jan 31 '16 15:01

user3661837


1 Answers

You have to tell the client to use a secure transport channel so that it uses https instead of http. This is true because the binding settings at the client must match the ones at the service side.

You can do this via configuration in the app.config file of the client, or you can do it via code like this:

var ws_http_binding = new WSHttpBinding();

ws_http_binding.Security.Mode = SecurityMode.Transport;

ChannelFactory<IInternal> factory = 
    new ChannelFactory<IInternal>(
        ws_http_binding,
        new EndpointAddress("https://MyMachine:8733/IInternal"));

var channel = factory.CreateChannel();
like image 91
Yacoub Massad Avatar answered Sep 28 '22 04:09

Yacoub Massad