Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host a WCF Service in a reference DLL via an MVC Website?

I hope that title is clear enough.

I have 2 projects, MyProject.Website (ASP.NET MVC3 Front End) and MyProject.WcfService. When i host the website, i'd rather not have to host two websites inside of IIS, i'd like to be able to host just MyProject.Website and inside of that reference MyProject.WcfService.

I know i can do this via ServiceHost, which should work, but is there a better way?

like image 751
Dean Thomas Avatar asked Jun 07 '11 08:06

Dean Thomas


People also ask

How do you call a WCF service reference in C#?

With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.


1 Answers

Check this post where i demostrated how you can host wcf service dll

Create, Host(Self Hosting, IIS hosting) and Consume WCF servcie

IIS hosting

  1. To host same WCF library in your application create WCF Web application project using WCF web application.
  2. Delete the files created in the IService.cs and Service.cs file from App_Code folder
  3. Include WCF library *.dll file which we created.
  4. Open Service.svc file and modify the single line in it

    -- <%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Service1" %>

  5. Change the web service WEB.Config file to to expose service to client. i.e you need to create Same element as listed above in in the app.config file of service library.

like image 79
Pranay Rana Avatar answered Sep 28 '22 08:09

Pranay Rana