2

I have an asp.net Website that has access to database and has functions which I want to allow 3rd party users to use.

Is it possible to add WCF project/ WCF service to my solution so i could let 3rd party member having access to my methods?

We tried myWebsite->Add New Item-> Wcf service/wcf data service but that doesn't seem to work.

Any help would be great.

Dror
  • 1,262
  • 3
  • 21
  • 34
  • Can you elaborate on how it doesn't work? You should add it as a separate project (WCF Service Application) – John Mc Nov 05 '12 at 13:56
  • Ok, But as since my project is Website, how could my WCF project recognize the class of my original websites? – Dror Nov 05 '12 at 14:03
  • Please explain what does not work. You can't add a WCF service because it's not available? Or the added service itself does not work? – w5l Nov 05 '12 at 14:19
  • I want to use WCF to expose my project , if i will add another WCF service application to my solution, I won't be able to use my older classes, the ones I want to expose to the WCF application, how can I make a WCF application that uses methods which belongs to a class from a different website/ – Dror Nov 05 '12 at 14:22
  • A great answer to this question was covered in this post: http://stackoverflow.com/questions/10374131/how-to-host-my-wcf-service-in-my-website – Mathew Paxinos Jul 13 '16 at 00:59

3 Answers3

1

It's not working because you are trying to add a reference to an existing service for consuming it. You want the exact opposite.

For this, you will have to create a separete project of type WCF Service in your solution.

More info on creating WCF Services can be found on MSDN.

Keep in mind that if you want to expose certain features through the service, you will have to factor the functionally out of the website to another project that both the WCF Service and the website can consume.

mcabral
  • 3,524
  • 1
  • 25
  • 42
  • Thanks mcabral, do you have any guide of how doing it? by "it"{ i mean the another project that both on wcf service and the website? – Dror Nov 05 '12 at 14:13
  • I don't know how your project is really structure, but I guess you will have to separate all the database access to another project. Some key concepts here are Separation of Concerns (http://en.wikipedia.org/wiki/Separation_of_concerns) and N-Tier architecture (http://en.wikipedia.org/wiki/Multitier_architecture) – mcabral Nov 05 '12 at 14:22
0

You should be able to add a new WCF service project from the solution root in Solution Explorer...

Right-Click >> Add >> New Project

It's not clear from your question what 'doesn't work' though.

Your newly added project will need to reference the existing project that contains the methods that you want to access. You should perhaps consider if your current design is appropriate - ensure that you have separated out your presentation code (this should be your website project) from the common business functions that you want to share (I would have this as a separate class library project in the solution). Your WCF project can then reference the common 'business logic' project.

To reference your 'business logic' project from the WCF project...

Right-Click (on WCF project) >> Add Reference

pswillies
  • 126
  • 4
  • Ok, But as since my project is Website, how could my WCF project recognize the class of my original websites? – Dror Nov 05 '12 at 14:06
  • You should put them in a common project which is shared by both/all projects – John Mc Nov 05 '12 at 15:56
0

Not sure what "doesn't work", but MSDN providers a walkthrough for adding a WCF service to a website here:

How to: Host a WCF Service in IIS

This has the step-by-step of creating a WCF (both markup and code) and adding the relevant web.config entries by hand rather than using the "Add Service" dialog.

If you create a separate project in your solution to run your services, you will need to reference your existing website project using the Add Reference option on the new service project. This will allow you to use the classes and functions defined in the existing project inside your new service project.

w5l
  • 5,341
  • 1
  • 25
  • 43