Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a .asmx file to asp.net MVC?

Tags:

asp.net-mvc

Is it possible to add a .asmx file to an MVC project and have .asmx code call the controller and have the controller return data to the .asmx code?

like image 957
Tony Borf Avatar asked Nov 24 '09 15:11

Tony Borf


1 Answers

Is it possible to add a .asmx file to an MVC project

Yes.

asmx code call the controller and have the controller return data to the .asmx code?

Yes.

var controller = new YourController();
var httpContext = new HttpContextWrapper(this.Context);
var routeData = new RouteData();
var requestContext = new RequestContext(httpContext, routeData);
controller.ControllerContext = new ControllerContext(requestContext, controller);

var result = controller.YourAction();

But I discourage to do that. Instead move common logic into a separate service layer and use that one.

like image 64
Dmytrii Nagirniak Avatar answered Sep 19 '22 12:09

Dmytrii Nagirniak