Reputation: 2034
I am currently working on an MVC project. It has a dependency on a service that is required to be run and perform task on set time intervals. This WCF service project is a separate project and I have integrated it into my MVC project.
Things worked fine for me till here, but the issue arises in WCF service application where now I need to call the action method of my MVC project controller class. One approach that I tried was to Add a reference to my MVC project and then try to access the action method but it gives me the error as follows :
The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
I want to know if my approach is the right thing that I am and if yes how to get rid of this error.
If not, what should I do to solve my issue.
Upvotes: 0
Views: 1903
Reputation: 7172
You have to think of them as separate websites, the wcf service wouldn't just instantiate a controller and run it, more it would create a webrequest and do either a get or post to it.
You can leverage the System.Net.WebClient class to do that.
All you need to do is decide if you want to post or get some data from the mvc site, and then use one of the methods on the webclient class to accomplish it.
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.100).aspx
That will detail the webclient class and how to use it. You will probably need an appsetting entry on the wcf service to point to the mvc site that you want to call, shouldn't be complicated at all
Upvotes: 1