WCF: the provided https URI scheme is invalid; expected "http". Parameter name: through when I call IInternal proxy = factory.CreateChannel (); by customer

App.config server:

<?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 factory.CreateChannel () method, I get an error

I am setting up a certificate

enter image description here

+5
source share
1 answer

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

You can do this through the configuration in the client's app.config file, or you can do it with the code as follows:

 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(); 
+3
source

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


All Articles