Deb
Deb

Reputation: 991

WCF Service Library Configuration (App.config) And Webapplication Config(Web.config) Issue

I have a Service Client Library project which has its own

app.config

.

This project is referenced in my Web Application. The problem is My web application throws following exception

Could not find endpoint element with name 'HttpEndPoint' and contract 'ServiceLibReference1.IDalService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

There is nothing wrong with the service. If i directly refer my service in the web application it works fine as client configurations get added to the web.config. But my requirement is to keep it in a separate library project.

The reason for the exception is service configurations are not added to the web.config. Should i always add them manually? Should not VS add corresponding configurations into web.config whenever a service library is referenced? or am i missing something ?

thanks

Upvotes: 0

Views: 365

Answers (1)

Tim
Tim

Reputation: 28530

Service libraries are, by design, intended to be used by (potentially) multiple different applications. Therefore, they don't use the app.config file included in the template - they will use the config file (web/app) of the application that is referencing them. This promotes code reuse - if you have certain methods that you are always using across multiple applications, it's easier to put them in a separate class library assembly. One benefit of that design is that you only need to change the code in one place to make the change effective for all using applications.

So yes, you will always need to add the service configuration to the specific application configuration file. Unfortunately, VS does not know to do this.

Upvotes: 1

Related Questions