“Could not find default endpoint element that references contract”

Hello,

recently, while developing a web application which uses quite a lot of ASP.Net web services, I ran across a following problem.

The application uses also a few C# class libraries, and I wanted one of those libraries to retrieve some data from a web service (let’s call it service A). So, within the class library, I added web reference to the desired web service, downloaded all needed definitions and wrote a method in order to check whether the connection to the web service was working. I also checked whether the app.config file of the class library has been modified. Positive – the Service Model section has been added, the binding has been configured. So far, so good. I compiled the assembly, and wanted to use it in another web service (service B), which serves some specific information to the presentation layer of my web application.

However, the instantiation of the SOAP client method threw the following exception:

Could not find default endpoint element that references contract ‘Client.ClientSoap’ 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.

The reason for the exception was quite simple: the web service B (which invoked the class library method that retrieved the data from service A), hasn’t been configured for usage of web service A. In other words, the Service Model section in the web.config file was missing.

Solution? Put the Service Model section generated in the app.config of the class library (as mentioned earlier) into the web.config file of the web service project.

Happy programming!

~ by Łukasz on 18 January 2010.

18 Responses to ““Could not find default endpoint element that references contract””

  1. Thank you so much. There are a ton of posts about possible issues that would cause this error, but this is the first one I have seen that actually pinpoints the issue I am having.

  2. Thanks for the most straightforward and accurate solution! I have read through so many posts that were not applicable and confusing. Thanks for your effort!

  3. Finally, a helpful post. Thank you very very much

  4. Hello, i have the same error in my wpf application.

    I create a user control that use one webservice to retrieve data in a combobox, and after that i use the same webservice (another method in this) to put data a database, the one parameter for the second method uses the selection from combobox, Is that the same as you describe above? the application when i run it works perfect, but at my visual studio designer give’s me the error you describe.

    Can you please help me with this? Thank you very much:)

    • hello, since it’s working ok at runtime, I’d presume that in designer mode VS is sowehow trying to perform databinding to that combobox.. But from your description I can’t really tell why it has problems..

      • hello, and thanks for the reply,

        I do a databindding at the combobox such “combobox … ItemsSource=”{Binding}” DisplayMemberPath=”Name” SelectedValuePath=”CityID” and from code i call the webservice which return a dataset ds and i call the combobox.datacontext=ds.table[0].

        from the app.config i took all the generated code from system.serviceModel untill /system.serviceModel and i put it at the web.config of my webservices, but at vs2010 i had warnings for binding tags, so i put at web.config the lines between client /client only. Then the program runs ok, but i have the error at the desiner, that can’t create my UserControl and the error you describe.

        Do you have any suggestions?
        Thanks🙂

  5. Thank you so much for his solution for this problem.

  6. Thanks. This article made me realize i forgot to update my web.config

  7. Thanks for that, my issue was slightly different but boils down to the same problem. I was trying to test the webservice call with unit tests and this resulted in the same error message. After I added an app.config file to the test project it worked perfectly.

  8. Brilliant, simple. Great post!

  9. Thanks for the post. I’m sure it saved me quite a bit of time! Luckily I found your post right away!

  10. Thanks alot for the post. You solved my problem🙂

  11. Si el tema es tan sencillo como copiar toda la seccion de modelo de servicios que genera el app.config en la seccion del web.config y listo todo funciona… Gracias

  12. Hi Even I have a simlar situation and your solutions is not working for me. I have class library in which i have referenced a web service and app.config is updated correctly. And in my WPF application im trying to use this class. WPF application config is also updated properly. but still i get this error when the prxoy object is created.

    • Hi Raghavendra, that would be pretty strange. Are you sure that the binding names and their corresponding endpoint entries have the same values?
      Best regards,
      Lukasz

  13. Show!!
    tks

  14. Thanks , it. works ;;

  15. Thank you, thank you. this error scared me,
    your solution saved me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: