Jim Aho
Jim Aho

Reputation: 11937

WCF - Is the services element mandatory

I think my question is rather simple, so I'll stick to the point:

Is it by any means possible to expose a service without specifying the services element and only the serviceHostingEnvironment element? I.e. would the below configuration be enough to host a WCF service? I'm asking because i've seen applications that - as far as I can tell - lack the services element, and I thought that was mandatory.

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    <serviceActivations>
        <add relativeAddress="Service.svc" service="Namespace.To.My.Service" />
    </serviceActivations>
</serviceHostingEnvironment>

Upvotes: 0

Views: 59

Answers (1)

Pankaj Kapare
Pankaj Kapare

Reputation: 7812

With WCF 4.0 you don't need explicit service configuration as opposed to prior versions. It automatically adds default endpoints if no endpoints are defined explicitly. Whatever configuration you mentioned in question is called File-less activation and you can activate service without even having physical .svc file. In WCF 4 you can define virtual service activation endpoints like one you have defined.

WCF detects what contracts are implemented by service and then method AddDefaultEndpoints adds one default endpoint per base address for each service contract implemented by the service. Note that this behavior is only when no explicit endpoints are added (either programmatically or through configuration). Should you add one explicit endpoint WCF stops adding default endpoints and it gives control to developer to customize it further.

Upvotes: 1

Related Questions