1
Answer

Hosting a Service in WCF

Photo of abhas mangal

abhas mangal

18y
6.9k
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)

hi there,

instead of creating / instanciating the end points and  protocols in code, why dont you go for modifying the web.config file. you just replace/add the <servicemodel> to </servicemodel> section from the auto generated config file from the WSDL, into the web.config file in your application, where you have to use the service.

once you add/replace the <servicemodel> tab section to your web.config file, all parameters will be set automatically. and you can access the service functionalities in your application by creating the client object of your service.

make sure that your client application contains the autogenerated proxy file in to your client applicaiton, as well as the settings according to the autogenerated web.config file.

then simply compile the client application and then you will ready to go.

and yet if you find any problem then feel free to email me on smartkhilit@aol.co.uk or reply here.

Cheers,

smartkhilit