0

I have created a class library - MyNS.MyClass. The Library has a Service Reference to a Webservice (added through Add Service Reference) - the Service Reference shows up as MyNS.VS in the Project. The class library is MyNS.dll. MyClass has a static method myStaticFunc which calls the Web Service

I have a separate C# console application where I add reference to this DLL. I have code there calling MyNS.MyClass.myStaticFunc. My project compiles fine. But when I run it, I get an exception

{"Could not find default endpoint element that references contract 'VS.MyObj' 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."}

To get rid of this exception, I have to also add a Service Reference in my Console Application & give it the same name (VS - however, here the namespace would obviously be my client app's namespace).

I don't understand why this needs to be done - it's the Library which is calling the WebService - the app is not calling it directly - and the Library does have the Service Reference. And why does the workaround work - in spite of the namespaces being different?

Dil85
  • 176
  • 1
  • 1
  • 14
user93353
  • 13,733
  • 8
  • 60
  • 122
  • Please have a look on below links :- http://stackoverflow.com/questions/352654/could-not-find-default-endpoint-element http://stackoverflow.com/questions/17583220/could-not-find-default-endpoint-element-that-references-contract – Anand Systematix Oct 17 '16 at 06:41
  • You should specify the endpoint in the .config file of your main app. – Alex Oct 17 '16 at 06:41
  • @Anand_Systematix - the linked question does not describe why this needs to be done – user93353 Oct 17 '16 at 06:44
  • The answers above are correct. You need to have endpoint configuration in your app.config file. Visual studio will add it automatically when you add a service reference to a project. That's why your workaround works. Open app.config in your library project and copy the settings to your app.config in your console app and it will work without adding a reference. – bib1257 Oct 17 '16 at 07:05

0 Answers0