0

I am building a class library (dll) in C# which calls a webservice. This will be consumed by different applications.

However, all these applications have to copy the "bindings" & "client" sections of the libraries app.config to the applications app.config for it to work. Otherwise the application throws an exception at runtime

{"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."}

FYI - My class library is - 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.

Is there a way to call the Webservice in the class library in some way so that this app.config change in the calling application is not necessary. Or some other workaround.

The owner of one of the calling applications says that he does not have an app.config in his application.

user93353
  • 13,733
  • 8
  • 60
  • 122
  • can you show us some code on how youre calling your class's. Also, can you show a screen shot of the properties of the library your wanting to import – Simon Price Oct 31 '16 at 08:52
  • http://stackoverflow.com/questions/2943148/how-to-programmatically-connect-a-client-to-a-wcf-service – Steve Oct 31 '16 at 08:57
  • also check out the answer to this question as this may help you http://stackoverflow.com/questions/690313/using-app-config-with-a-class-library – Simon Price Oct 31 '16 at 08:57
  • http://stackoverflow.com/questions/835613/wcf-how-can-i-programatically-recreate-these-app-config-values/839941#839941 – Steve Oct 31 '16 at 08:57
  • Please check if any of those answers are your case and close the question if duplicate – Steve Oct 31 '16 at 08:58
  • All above can help, and probably use an external config file and link back with configSource is the easiest. – Lex Li Oct 31 '16 at 09:43
  • @LexLi - the question you have linked as duplicate doesn't really help me at all. OTOH, some of the questions pointed to by others in the comments do help immensely. – user93353 Nov 01 '16 at 04:39
  • @user93353 post what you used as an answer and accept it next time and close a question as early as possible. Don't wait till it is closed in another way. – Lex Li Nov 01 '16 at 05:34
  • @LexLi - you closed it even before I could look at any of the comments. I think you should at least make sure you understand the question & which answer correctly answers it before you close it as a duplicate. – user93353 Nov 01 '16 at 06:05
  • @user93353 as I commented firstly, your question is in all ways duplicate to existing discussions (other comments are the proof). I chose the "easiest" one I think, and I don't think that's a bad idea on my side. Make sure you search carefully before posting. – Lex Li Nov 01 '16 at 08:53
  • @LexLi - the easiest one did not answer my question at all. – user93353 Nov 01 '16 at 09:27

0 Answers0