including a WCF service project in my website solution and referencing it - c#

Im new to .net and I have my website solution and I added my database WCF service to the solution, how can i reference the service's interfaces? I will be making changes to the service as i develop, do I have to build/Deploy the service every time or can i just reference the .svc file somehow?

[nkvu - moving out of the comments & as an answer in case it needs to be found later...]
If your WCF service is a separate project in the same solution as your web project then you should be able to follow the instructions here under the "To add a reference to a service in the current solution" heading...After you make changes you can just use the instructions under "Update a Service Reference" to make sure your web project is in sync with the service changes

Related

UWP VS2015 .Net 4.61 Add Web Reference Button Missing

Any help would be greatly appreciated!! I have scoured the web trying to find an answer. I am writing a UWP app that will be deployed to the Xbox platform. I need to access a web service written in .Net 2.0. In earlier versions of .Net / Visual Studio the Add Web Reference Button was hidden in a panel accessed through ->Add Service Reference ->Advanced ->Add Web Reference. With latest build of VS2015 the Add Web Reference Button is missing. Did this completely go away or is it hidden even deeper in the environment somewhere?
XML Web Services, also known as ASMX services, were the predecessor of Windows Communication Foundation (WCF). You can access Web Services by adding a service reference just as you would for any other WCF service.
A service reference enables a project to access one or more Windows Communication Foundation (WCF) services. Use the Add Service Reference dialog box to search for WCF services in the current solution, locally, on a local area network, or on the Internet.
For more info, please How to: Add, Update, or Remove a Service Reference.

Can't add service reference to client class for WCF project within same solution

I'm working through an example on a website to create and consume a WCF service. I've created the service which is hosted in a windows application.
As per the instructions on the site I've created a ClientApp console app within in the same Visual Studio solution. Now the problem is that I cannot create a service reference to the WCF host project.
If I run the host project the Service is switched on and I can verify this by visiting the url in my browser. However, I cannot add a service reference to my client project while another project is running. The "Add Service Reference" option is greyed out. Presumably this is since they're in the same solution in Visual Studio.
If I try and add the reference when the host project is not running then I can get into the "Add Service Reference" screen but no services can be found (presumably because the WCF service is no longer running
How can I get around this?
The solution explorer is as in the image:
You could also try to start the WCF service in Visual Studio, then select "Detach All" from the Debug menu. This should let the service continue to run in the background, yet open Visual Studio to let you add service references.
In the Add Service Reference dialog, click the Discover button and select Services in Solution:

Can't add service reference to my project

I have a solution which contains :
- a website hosted on my local IIS
- a project that defines a WCF web service
- 2 other projects which are assemblies used by the website
I added a console application to quickly test the webservice but when I right click on the project, context menu doesn't contains the "add service reference" entry (but it's present when I right click on the website).
I had done this in the past without problem, why doesn't it work anymore ?
Edit :
If I create a new console project in an empty solution, I can add a service reference.

Combining WCF Service Library and WCF Service Application

Thanks to Stack Overflow and a few other sites, I understand the difference between the WCF LIbrary and WCF Service Application templates.
Briefly the Library is a DLL that allows for multiple types of hosting. It does not have a .svc file. While the Service Applications template is created specifically with IIS in mine with a .svc file.
I read that WCF Service Library is the best way because it is the most flexible. But I NEVER see instructions on how to do it apart from using the WCF Service Application template.
Is it difficult to go from WCF Service Library to hosting on IIS from scratch? I have two books on WCF and I've read numerous articles and none of them cover how to create a svc file using only the WCF Service Library and No WCF Service Application. Why?
Nigel Shaw also mentions on the following link that there are limitations to using the Library option. What is the purpose of WCF Service Library?
Basically What I want to do is host the WCF Service on both IIS and a Windows Service. Thus it appears that the combined way is the best way. Nevertheless, I'm trying to learn why there aren't more instructions on using the WCF Service Library.
Ok, I did find a couple of articles that seem to use an ASP.NET Web Application and tells you how to create a text file for the svc file.
This article: http://debugmode.net/2010/12/25/wcf-service-library-creating-hosting-and-consuming-wcf-service-with-wcf-service-library-project-template/
and this one: http://danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-studio-2008/
But what I still don't understand is why is the ASP.NET Application still needed? And If i add a svc file does it get placed in the wwwroot directory (that seems to be where the WCF Service Application places it .svc file?
Thanks!
A WCF Service Library has to be hosted in order to be used - you can host it in IIS, a Windows Service or some self-hosted option (like a console app, WinForm, WPF, etc).
In the last two links you provide, they're demonstrating how to host the library in an ASP.NET service application, but you don't have to use that project template to host it. It's simply one option out of several.
You can create an IIS-hosted implementation of your class library without using a VS project template, but you'll need to manually add the .svc file and the Web.config. I have done this several times:
Create a folder (I normally put mine in the wwwroot folder of inetpub, but you can put it wherever you desire).
Create a bin folder in the folder you created in step 1, and put the WCF service library and any other required assemblies in it.
Add a .svc file with the appropriate markup in the folder created in step 1.
Add a Web.config with the appropriate service model configuration in the folder created in step 1.
Create an application in IIS that points to the folder you created.
Now you have an IIS-hosted instance of your service. You can then use another copy of the WCF service library for your Windows-Service hosted instance.

Get Webservice WSDL in different project within same solution

I have a Web Service Project and a Web Site Project both within the same solution. I have a simple link on a web page within the Web Site Project that needs to point to a web services WSDL (example: Webservice.asmx?WSDL) within the Web Service Project. Is this possible?
Would I be better off using a hardcopy of the WSDL document and just putting that in my web site project?
I don't believe so. You will need to have the webservice run, in either IIS, or through visual studio.
Why not add a Web reference to the Webservice (Browse for "Web services in this solution") ?
That's what adding the reference does, basically... along with creation of the class mapping. Then you could always update references without having to worry about hard coded wsdl links.

Categories

Resources