linda
linda

Reputation: 1

WCF security exception

i have a console application that is used to launch (open) my wcf services i have a web application that uses these services. how can i implement transport level security with authentication?

i have this till now: service:

 WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
 ServiceHost svh = new ServiceHost(Type.GetType(MyClass);       
 svh.AddServiceEndpoint(IMyClass, binding, "https://localhost:9090/ServiceTest");                       
 ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
 sb.HttpsGetEnabled = true;
 sb.HttpsGetUrl = new Uri("https://localhost:9090/ServiceTest");
 svh.Description.Behaviors.Add(sb);
 svh.Open();

Client:

 WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
 EndpointIdentity endpointIdentity = EndpointIdentity.CreateDnsIdentity("localhost");
 EndpointAddress endPoint = new EndpointAddress(new Uri("https://localhost:9090/ServiceTest"), endpointIdentity, new AddressHeaderCollection());    
 ChannelFactory<T> engineFactory = new ChannelFactory<T>(binding, endPoint);
 T MyService = engineFactory.CreateChannel();

i first launch the console application... and all my services are open.
but when i call a method in the service from the webapplication i get an exception saying:

 An error occurred while making the HTTP request to 
 https://localhost:9090/ServiceTest. This could be due to the fact that the
 server certificate is not configured properly with HTTP.SYS in the HTTPS case. This 
 could also be caused by a mismatch of the security binding between the client and the 
 server.

when i googled... i found that i need to set ssl certificates on iis... but my services are hosted on a console application... then how can i set these certificates? moreover how can i set a username and password for to allow usage of the service?

Upvotes: 0

Views: 1181

Answers (2)

BrandonZeider
BrandonZeider

Reputation: 8152

+1 on the @Aliostad answer.

Another option for you is to use a different binding if you can. You can get Transport security by default with a NetTcpBinding for example, without having to setup certificates. This approach would be much less work.

Upvotes: 0

Aliostad
Aliostad

Reputation: 81660

Have a look here.

You need to setup your certificate.

Upvotes: 2

Related Questions