I have a WCF that is in use now for over a year, coded by someone else and i'm trying to refactor it but the way the folder structure is organized and the svc.cs file containing the methods is not what I am used to from WCF samples I completed.
Here is what I'm trying to achieve. Since none of the settings changed over the last year I am asked to hardcode all the service's settings in code. The service is hosted within big and existing web application(and I have to leave it in there), the svc file contains the method getting called by the client, and this svc.cs file is not located at the root of the virtual directory but deeper, lets say <virtualDirectory>/WebServices/PotatoWebService/PotatoWebService.svc
, does having it not in the virtual directory root cause any problem?
Since I am moving the configuration out of the config file, I am now creating the service, host, endpoint, binding within the web application's global.axax.cs file, at ApplicationStart()
, is that the right place to start this service within a web application?
Is it possible to move everything in code, not just the endPoint but also the entire content of the behavior, service and system.ServiceModel found in the web.config file, in order to 'clean' the config file, and stop scaring support and config managers with settings they don't need?
If it is, I have been trying for 2 days to get this to work without success. What I have now according to netstat is a service up and running but when I open my svc file in the browser an exception pops saying the service dosent have any endpoints defined, although according to nstat I have a service running:
netstat -a | find LISTENING
...
TCP machineName:8097 elamontagne.potato.com:0 LISTENING
...
So I have a service running but a svc file that is not aware of it and can't use it's endpoints, a client trying to contact the service and can't find it because service has no endpoint, any tips to narrow down the problem, tips for trouble shooting this situation?
//Address
string hostingAddress = "PotatoVirtualDirectory/PotatoService/PotatoService.svc";
// Binding
BasicHttpBinding PotatoServiceBinding = ConfigurePotatoServiceBinding(serviceSecurityMode);
// Contract
Type PotatoContract = typeof(IPotatoService);
// Host
this.PotatoServiceHost = new ServiceHost(typeof(PotatoService), new Uri("http://localhost:8097"));
// Endpoint
this.PotatoServiceHost.AddServiceEndpoint(PotatoContract, PotatoBinding, hostingAddress);
// Behavior
ConfigurePotatoServiceBehavior(this.PotatoServiceHost, PotatoServiceBinding);
// Name
this.PotatoServiceHost.Description.Name = "PotatoNamespace.PotatoService";
//Start!
this.PotatoServiceHost.Open();
This compiles and run, it gives me an running service in opened state. The client can't find it at it's usual location, and the svc file complains it has nohting in the web.config and wants an endpoint ServiceHasZeroAppEndpoints: "Service has zero application (non-infrastructure) endpoints"
I've step through the code in debug and all looks fine, service is openend, what I am missing, any tips to narrow down this problem?
Edit: Deriving from the service host factory worked well, thanks!