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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With