Friday 19 June 2009

Add web reference as a service reference

With the introduction of WCF I am attempting to add my existing web service (ASMX) to a class library but using WCF service references.

So I have this web service URL i.e. http://localhost/ChoicesSurveyWS/SurveyWS.asmx
  • I create a new class library project.
  • I right-click on the new class library and select "Add service reference".
  • A dialog pops up and I place my web service URL into the "Address" bar.
  • Click "Go".
  • Type in a new namespace name i.e. SurveyService.
  • Click "Ok".


Now a service reference is added to the project and an app.config file.
  • Create a new console project to be the client (consumer) of the web service.
  • Add the class library we created as a project reference to the console project.

*NB* MOVE THE app.config FILE FROM the class library into the console project. This will prevent you getting an error like this:

Could not find default endpoint element that references contract in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element match