I am working on a project that uses WCF service. I have built the service, configured the web.config file, deployed it on a IIS 7 server. The service is accesed through HTTPS (on my dev machine, i have self-created the certificate). Everything is fine when a create the ServiceReference in Visual Studio 2010, it creates the client and it works fine.
What i need is to create a client programatically (need a little flexibility), so when i try to connect "manually", it gives me a error like this:
The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
The code for web.config is: (i hope there is nothing wrong in it)
<system.serviceModel> <services> <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior"><endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="WcfService1.IService1" /><endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/></service></services><behaviors><serviceBehaviors><behavior name="WcfService1.Service1Behavior"><serviceMetadata httpsGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="True"/></behavior></serviceBehaviors></behaviors><bindings><wsHttpBinding><binding name="TransportSecurity"><security mode="Transport"><transport clientCredentialType="None"/></security></binding></wsHttpBinding></bindings></system.serviceModel>
The procedure i wrote to access the WCF service is:
void proc() { string ADRESASSL = "https://localhost/ServiciuSSLwsBind/Service1.svc"; WSHttpBinding bind= new WSHttpBinding(); EndpointAddress ea = new EndpointAddress(ADRESASSL); var myChannelFactory = new ChannelFactory<IService1>(bind, ea); IService1 client = null; try { client = myChannelFactory.CreateChannel(); client.RunMethod1(); client.Close(); //((ICommunicationObject)client).Close(); } catch (Exception exc) { MessageBox.Show(exc.Message); if (client != null) client.Close(); } }
The code for IService1
[ServiceContract]public interface IService1 : IClientChannel{ [OperationContract] int RunMethod1(); //....................................}
It seems i am doing something wrong here, the procedure raises the Exception i mentioned. Something more i must do to work, but i didn't figured it out.
Thanks in advance for any advice you can give me.