0

I have searched a lot for methods of hosting the WCF and found them to work, however, in my a Solution I have WCF Service Project(it has a web.config with some connection strings) and a ASPX.NET project( it also has a web.config), could any one please clarify on how I can host them in a website.

Thank you.

misha
  • 2,760
  • 3
  • 28
  • 30
surpavan
  • 1,372
  • 7
  • 34
  • 66

3 Answers3

1

For hosting a WCF service you have the following options:

  • WinForms applications
  • Console applications
  • Windows services
  • Web applications (ASP.NET) hosted on Internet Information Services (IIS)
  • WCF services inside IIS 7.0 and WAS on Windows Vista or Windows Server code name "Longhorn"

See here for more information on hosting a WCF service.

For hosting an Asp.Net application I'd recommend using IIS, see here for how. However, using WSE it is also possible to host it as a windows service. See here for how.

Rich O'Kelly
  • 41,274
  • 9
  • 83
  • 114
1

Its simple, you just need to add a '.svc' file to your ASPX.net project. e.g. Service1.svc

Then add the following code to the file

<%@ ServiceHost Language="C#" Service="WCFServiceProject.Main" %>

The WCFServiceProject.Main is the fully qualified namespace and name of the class that provides the functionality of your service

You will also need to register the svc extension in IIS for it to work if you haven't already. And don't forget to add the reference to the WCF service project to the aspx.net project.

If you want to create the service dynamically then see my question for some hints Creating wcf service within IIS in code

Just reread the updated (edited) question. You'll need to copy the connection details from the WCF service project into your asp.net project.

Community
  • 1
  • 1
Keith K
  • 2,893
  • 4
  • 33
  • 43
  • Thanks for the info keith. However, after building the WCF Service the connection string cannot be edited on published server since it is DLL. As per your advice, if I add the connection string to my Aspx site web config, it wont work that way, does it? – surpavan Nov 29 '11 at 18:39
  • If your WCF project is part of your ASPX site then the web.config of the site becomes the web.config of the WCF Project. The config file of the WCF project is ignored. Your WCF service will then read the connection strings defined in the ASPX project. – Keith K Dec 01 '11 at 12:22
1

Do you want any other client to access this WCF service?

If not, just keep a .svc file in your existing web application and use it whenever you need.

If yes, host the WCF project as a website in IIS, console or WAS and refer it from your aspx web application.

Keith K
  • 2,893
  • 4
  • 33
  • 43
  • I want the WCF to serve other apps also. For now, I am testing my code on a free host that gives me a sub-domain and with 1 sql server db only, in this case how can I achieve this? Thanks Praveen. – surpavan Nov 29 '11 at 18:40
  • 1
    in that case you can host your wcf service as a website on IIS. then any web application can add it's web reference and consume it. – PraveenLearnsEveryday Nov 30 '11 at 03:49
  • So, a wcf must be hosted in another site, or a sub domain so that more than one web configs can be accommodated and also to be referred. Thank you. – surpavan Nov 30 '11 at 11:31
  • Yes. hosting WCF on IIS as a different site will make sure that any application can consume it be it a windows or a web app using different endpoints provided in wcf web.config. – PraveenLearnsEveryday Nov 30 '11 at 11:54