Returning an HTML Page from a Creatio Configuration Service

A Creatio configuration service is a WCF service that is typically used to create web services that consume and provide JSON. However, it is possible to also change the content type of the data returned to other types. This article will look at creating a configuration service that returns a HTML page that can be viewed like any HTML page.

We’ll create a service with an exposed GET method. We’ll set the content type to text/html and then create some HTML as a string which will be returned as a stream. Let’s look at the code for the service:

namespace Terrasoft.Configuration
{
    using System;
    using System.Web;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.ServiceModel.Activation;
    using System.IO;
    using System.Text;
    using Terrasoft.Core;
    using Terrasoft.Web.Common;
	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class UsrTestService : BaseService
    {
        [OperationContract]
        [WebInvoke(Method = "GET")]
        public Stream GetHtmlPage()
        {
            WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
			
            var page = @"
                <html>
                    <head><title>Test HTML Page</title><head>
                    <body>
                        <h1>Hello</h1>
                        <p>This is a test HTML page returned from Creatio</p>
                    </body>
                </html>";
            
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(page));
            return stream;
        }
    }
}

The end result is that we can navigate to the web service in our browser using the URL:

https://creatiourl/0/rest/UsrTestService/GetHtmlPage

And we’ll see the following page:

Note, you can also create this as an anonymous web service so it can be called outside of Creatio as well.

Want content like this delivered to your inbox? Sign up for our newsletter!
ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *