Hosting WCF and ASP.NET application under same virtual directory in IIS
Posted by codingsense on October 28, 2009
I had created a WCF service and an ASP.NET application which would consume the service, I hosted both in separate virtual directories and it was working very fine. After some days and lots of changes I noticed that the dlls and other common files used in both WCF and ASP.net application, had to be replaced in both the virtual directories to synchronize them.
So I planned to see if it’s possible to host both the application under same virtual directory and got a solution of merging the web.Config files of both the application. Now I have to replace the necessary assemblies or files in only one virtual directory and it has made my job lot easier.
Following are the steps that were followed.
Note: At the end I removed the WCF virtual directory and made my ASP.Net virtual directory to host both the application.
- Copy the required files (Except Config file) from WCF virtual directory and place them appropriately in the structure in ASP.net virtual directory. (Eg: .svc file in the main folder and other required dlls into the bin folder)
- Now we have all files in appropriate locations, just we need to do is to merge the web.config files to contain both Service as well as client configuration.
- Open the web.Config file that was in WCF virtual directory and copy the <services> tag and <behaviour> tag with all its contents.
- Open the web.Config file of ASP.net application and paste the copied contents in the <system.serviceModel> tag.
- Copy the new path of the service by brosing the .svc file from IIS manager (inetmgr.exe) Note: If it wont run successfully check for required setting for the service in web.Config.
- In the web.Config in the ASP.net virtual directory and change the address of all the endpoints to point to the new location of service.
- Run the main application.
After following the above procedure I successfully hosted both applications under same virtual directory.
If you have any problem while following the steps or any other problem related to WCF or IIS you can please share it with me.
Happy Learning 🙂