Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:22:17+00:00 2026-05-24T21:22:17+00:00

I have a WCF REST service that takes some parameters and sends an email.

  • 0

I have a WCF REST service that takes some parameters and sends an email. The template for the email is an MVC3 action. Essentially I want to render that action to a string.

If it were an ASP.NET WebForm, I could simply use Server.Execute(path, stringWriter, false). However when I plug in the path to my action, I get Error executing child request.

I have full access to HttpContext from my service (AspNetCompatibilityRequirementsMode.Allowed).

I know there are other answers out there for rendering actions to strings from within the context of a controller. How do I do this when I’m outside that world, but still on the same server (and, for that matter, in the same app)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:22:18+00:00Added an answer on May 24, 2026 at 9:22 pm

    I cobbled together an answer based on several different google searches. It works, but I’m not 100% sure it’s as lean as it could be. I’ll paste the code for others to try.

    string GetEmailText(TemplateParameters parameters) {
        // Get the HttpContext
        HttpContextBase httpContextBase = 
            new HttpContextWrapper(HttpContext.Current);
        // Build the route data
        var routeData = new RouteData();
        routeData.Values.Add("controller", "EmailTemplate");
        routeData.Values.Add("action", "Create");
    
        // Create the controller context
        var controllerContext = new ControllerContext(
            new RequestContext(httpContextBase, routeData), 
            new EmailTemplateController());
    
        var body = ((EmailTemplateController)controllerContext.Controller)
                   .Create(parameters).Capture(controllerContext);
        return body;
    }
    
    // Using code from here:
    // http://blog.approache.com/2010/11/render-any-aspnet-mvc-actionresult-to.html
    public class ResponseCapture : IDisposable
    {
        private readonly HttpResponseBase response;
        private readonly TextWriter originalWriter;
        private StringWriter localWriter;
        public ResponseCapture(HttpResponseBase response)
        {
            this.response = response;
            originalWriter = response.Output;
            localWriter = new StringWriter();
            response.Output = localWriter;
        }
        public override string ToString()
        {
            localWriter.Flush();
            return localWriter.ToString();
        }
        public void Dispose()
        {
            if (localWriter != null)
            {
                localWriter.Dispose();
                localWriter = null;
                response.Output = originalWriter;
            }
        }
    }
    public static class ActionResultExtensions
    {
        public static string Capture(this ActionResult result, ControllerContext controllerContext)
        {
            using (var it = new ResponseCapture(controllerContext.RequestContext.HttpContext.Response))
            {
                result.ExecuteResult(controllerContext);
                return it.ToString();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC3 and a WCF REST service that are both hosted in
I have a WCF REST service that I customized from the VS2010 online template.
I have an asp.net 4 application that hosts a WCF REST service via WebServiceHost...
I have a C# REST Service in WCF that sits on top of an
Let's say that I have specified the following WCF REST Service at the address
I have developed a sample WCF REST service that accepts that creates an Order
I have a self hosted WCF Rest service that I am using to simulate
I am trying to build a REST & json based WCF service that takes
I have a WCF REST web service that is hosted via a service route
I have a WCF WebApi Rest service that has the following endpoints: [WebGet(UriTemplate =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.