1
Answer

Hosting a Service in WCF

Ask a question
abhas mangal

abhas mangal

17y
6.4k
1
Hi, I have created a Windows Service in Visualstudio 2005 and created a service host in the OnStart() method to run the service host created when the windows service is run. To run I created a setup project and configure it to install my service on the local machine but when I am running the service an error is generated and is written in the event viewer as : Cannot find the X.509 certificate using the following search criteria: StoreName 'TrustedPublisher', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue 'ADIANCE08\Administrator'. The code written to host the service is as follows : try { NetTcpBinding binding = new NetTcpBinding(); binding.PortSharingEnabled = true; binding.TransferMode = TransferMode.Buffered; host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust; binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; host.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.TrustedPublisher, X509FindType.FindBySubjectName, @"ADIANCE08\Administrator"); host.AddServiceEndpoint(typeof(IServer), binding, "net.tcp://ADIANCE08:2600/MyFile"); host.Open(); } catch (Exception ex) { eventLog1.WriteEntry(ex.Message, EventLogEntryType.Error); eventLog1.Close(); } I am using the same above code and hosting the service successfully in the Windows Application(WPF) without any error. Can anyone suggest me how to configure my service successfully in Windows Service Based Application?Please let me know what I miss in the above lines of code also.

Answers (1)