Relationship between configuration in app.config or web.config and code in WCF

How the service host in WCF interacts with the configuration from web.config or app.config. When I create the service host, I only specify the URL in the service host constructor and service class.

But in app.config or web.config, I have another list of endpoints, each with its own url. So how does wcf handle this situation? What endpoint is required from app.config or web.config?

+8
c # wcf
source share
2 answers

The endpoint address refers 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 the host URL of the service http://localhost:7777 , then you will expose your service http://localhost:7777 and the metadata to http://localhost:7777/mex .

+2
source share

Thus, in general, your interaction depends on several factors: your hose environment, code, and the settings of your website or application.

According to MSDN ( http://msdn.microsoft.com/en-us/library/ms733749.aspx ): There are two ways to specify the endpoint addresses for a service in WCF. You can specify the absolute address for each endpoint associated with the service, or you can specify the base address of the ServiceHost service, and then specify the address for each endpoint associated with this service that is defined with respect to this base address. You can use each of these procedures to specify the endpoint addresses for the service in configuration or code. If you do not provide a relative address, the service uses the base address.

You should also pay attention to your placement environment. For example, IIS itself generates your base address for the endpoint (even if it is specified in config), meanwhile, read it from the configuration on separate hosts.

The link above describes in great detail the features of determining your address in code or configuration and its dependence on the host environment

+1
source share

All Articles