Thanks, David. I think I'm having trouble before I get to the serialization details. The method signature seems to be unreachable since it throws a 404. I wish the Kentico documentation included an example. Below is my test code. I'm attempting to reach the method using the following request on my dev environment:
https://127.0.0.1/rest/macro/TestCustomMacro.TestMacro
Do you think I should call the method using "TestCustomMacro.TestMacro" as defined by my class and method names? Or am I doing this wrong? Thanks!
using CMS;
using CMS.MacroEngine;
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;
/// <summary>
/// Summary description for TestCustomMacro
/// </summary>
// Makes all methods in the 'TestCustomMacro' container class available for string objects
[assembly: RegisterExtension(typeof(TestCustomMacro), typeof(string))]
// Registers methods from the 'TestCustomMacro' container into the "String" macro namespace
[assembly: RegisterExtension(typeof(TestCustomMacro), typeof(CMS.MacroEngine.SystemNamespace))]
public class TestCustomMacro : MacroMethodContainer
{
[MacroMethod(typeof(string), "Test macro", 0)]
public static object TestMacro(EvaluationContext context, params object[] parameters)
{
clsTestObject testObject = new clsTestObject();
testObject.PropA = "valueA";
testObject.PropB = "valueB";
testObject.PropC = "valueC";
XmlSerializer xmlSerializer = new XmlSerializer(testObject.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, testObject);
return textWriter.ToString();
}
}
//[MacroMethod(typeof(clsTestObject), "Test macro 2", 0)]
//public static object TestMacro2(EvaluationContext context, params object[] parameters)
//{
// clsTestObject testObject = new clsTestObject();
// testObject.PropA = "valueA";
// testObject.PropB = "valueB";
// testObject.PropC = "valueC";
// return testObject;
//}
}
[Serializable()]
public class clsTestObject : ISerializable
{
public string PropA;
public string PropB;
public string PropC;
public clsTestObject()
{
PropA = "initA";
PropB = "initB";
PropC = "initC";
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("PropA", PropA);
info.AddValue("PropB", PropB);
info.AddValue("PropC", PropC);
}
}