0

I am intending to provide access to a web service for an ASP.NET web application through a class library, and have been experimenting with a simple weather service.

In case it makes a difference I am using Visual Web Developer 2010 Express.

The interface between the web application and the class library is a simple string passed and string returned to a single method of a single class e.g.

String forecast = LibClassInstance.GetForecast("Madrid");

I added the Service Reference to the class library using AddServiceReference and created my call to the service through the automatically generated proxy classes. So far so good.

I then went to call my simple GetForecast method from my web application and got a long error message to the effect that the service might not have been configured in my project's Web.config file. After adding the Service Reference to my application project as well, it all worked as expected. I was hoping that the service behind the class library code would be hidden from its clients.

Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?

Akram Berkawy
  • 4,920
  • 2
  • 19
  • 27
Alan Gee
  • 281
  • 1
  • 14

1 Answers1

1

Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?

It isn't necessary. But you do need to configure the service in Web.Config - as a starting point you can copy the system.serviceModel section that was generated in the app.config of your class library when you added the Service Reference.

Joe
  • 122,218
  • 32
  • 205
  • 338
  • Thanks. I think what you're saying is that the application does at least need to know about the service even though it doesn't access it directly. – Alan Gee Oct 25 '12 at 11:51