A client makes a call into a custom library function. Library function in turn makes a call to an external web service/WCF service by using add service reference and throws an exception.
This is very common in Excel UDF, Office customizations where reusable components/DLLs/Library Projects are used to access business functionalities exposed via web services.
Could not find default endpoint element that references contract 'ServiceReference2.IService1' 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 contract could be found in the client element.
Create an app.config file in the client’s Bin(or lookup) directory. Copy System.ServiceModel node from Library project’s app.config file to client’s app.config file.
Since client is not directly calling the web service/ WCF service, it is expected that no web service configuration information is required at the client and the library project should be able to take care of interaction with web service. And hence troubleshooting is limited between the library and web service.
But runtime looks for the web service end point information in the caller’s application directory i.e. client’s app.config file and look up fails. So the solution is to copy the complete System.ServiceModel node from library’s app.config file to client’s app.config file.