How to add service reference in client project?

13,637

Solution 1

You need something to be running the service, with the metadata being published. This can be IIS, but also any other valid hosting option.

I often write a simple console application to self-host a WCF service, exactly for this reason. It makes it super easy to debug, as well as to update service references during the earlier phases of development, and can dramatically simplify work when working on the client and server simultaneously.

Solution 2

You don't have to publish it under IIS, with WCF you can host your sevice in a console application or windows forms app or as Windows service or under IIS.

In your client app you will just need to right click and add service reference.

update:
Simple WCF Example

Solution 3

Typically you would host your WCF service under IIS in its final location (because then it can determine the URL for you also), however, you could also just run it directly from visual studio, and then in your client, in Visual Studio, you can right-click on the "References" and choose "Add Service Reference", and point it to your WCF service, wherever it is running.

The application will then have its WCF client built for it off the WSDL.

Note that it will also set that URL for the service in your app.config, so if you did not have the service hosted in its final production URL, you will have to change that URL in the client when you move it to production.

So to answer your question more directly; yes, your service should be running when you "Add Service Reference" from the client application.

Share:
13,637
Silverlight Student
Author by

Silverlight Student

Updated on June 12, 2022

Comments

  • Silverlight Student
    Silverlight Student almost 2 years

    I am totally new to WCF so please indicate if you find something that I am doing totally wrong here. I have created a WCF service project (my service class is dervied from ServiceBase class) with endpoint address binding set to basicHttpBinding. Now I need to create a client application that can call some APIs from this service. My quesion is that in my client application how can I add service reference to that service. Do I need to publish this service first under IIS (which mean I have to have IIS available on the machine too) or is there some other way of adding service reference too.

  • Silverlight Student
    Silverlight Student almost 13 years
    When i right click and do add service reference it bring up this dialog where it is asking to enter an "Address". How do I provide that address? Do I need to run the service first?
  • Reed Copsey
    Reed Copsey almost 13 years
    @Silverlight Student: Yes. THe service needs to be running, and needs to have a metadata endpoint published. You'd enter the address of that. Look at the service's app.config/etc for the address.
  • Jethro
    Jethro almost 13 years
    @Silverlight Student: As Reed said above you will need to first host the service, try hosting it in a console app. very easy.
  • Silverlight Student
    Silverlight Student almost 13 years
    Are you saying to convert my services project to a console app first? May be an example might help although i am reading the Simple WCF Example link that you provided to see if that can help creating the console app
  • Jethro
    Jethro almost 13 years
    @Silverlight Student, let me know if you still need help after going through that example.