Reputation: 2708
How does a service host in WCF interact with the configuration from the web.config or app.config. When I create a service host I only specify an url in the service host constructor and the class of the service.
But in the app.config or web.config I have another list of endpoints, each with it's own specific url. So how does wcf handle this situation? Which endpoint does it take from the app.config or web.config?
Upvotes: 8
Views: 442
Reputation: 8937
So in general your interaction depends on several factors - your hosing environment, you code and your web or app settings.
According to MSDN (http://msdn.microsoft.com/en-us/library/ms733749.aspx): There are two ways to specify endpoint addresses for a service in WCF. You can specify an absolute address for each endpoint associated with the service or you can provide a base address for the ServiceHost of a service and then specify an address for each endpoint associated with this service that is defined relative to this base address. You can use each of these procedures to specify the endpoint addresses for a service in either configuration or code. If you do not specify a relative address, the service uses the base address.
Also you must pay attention on your hosting environment. For example IIS itself generates your base adress for endpoint (even if it is specified in config), meanwhile in self-hosts read it from configuration.
The above link greatly describes the features of specifing your adress in code or configuration, and its dependance on your host environment
Upvotes: 1
Reputation: 31071
The address of the endpoint is relative to the base address of the service host. For example, if you had these endpoints:
<service name="MyService">
<endpoint address="" binding="ws2007HttpBinding" contract="IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
and a service host url of http://localhost:7777
, then you would be exposing your service on http://localhost:7777
, and the metadata on http://localhost:7777/mex
.
Upvotes: 2