How to add service reference in client project?
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 servic开发者_开发百科e 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.
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.
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
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.
精彩评论