Below is the example of using the ForeExec operation to execute method with sending object in the JSON format. The request contains name of the executed method and moniker of the development environment object containing method implementation. The JSON structure is sent as a parameter value. The operation result will also be in the JSON format. The executed method has the following syntax:
The C# example uses the FindObjectById function, which code is given in the Getting Object Description by Its Identifier example.
{
"ForeExec" :
{
"tFore" :
{
"id" : "AHHCPKBHELFGGOAEJJPPPODMMPIBEDEEALGKJDIIBMIMFFJM!M!7360"
},
"tArg" :
{
"methodName" : "WorkWithJson",
"args" :
{
"it" :
{
"k" : "1",
"jsonValue" :
{
"Data" :
{
"IntValue" : "123",
"DblValue" : "123.321",
"StrValue" : "ABCDEF"
}
}
}
}
}
}
}
{
"ForeExecResult" : "{"json":{"ExecResult":true,"ExecDay":"31.07.2025 00:00:00"}}""
}
public static ForeExecResult ExecMethodWithJson(MbId mb, string assmId, string methodName)
{
var somClient = new SomPortTypeClient(); // Proxy object for operation execution
// Operation execution parameters
var tExec = new ForeExec()
{
tArg = new ForeExecArg()
{
methodName = methodName,
// JSON object as parameter value
args = new OdArg[1]
{
new OdArg(){ k = 1, jsonValue = new System.Xml.Linq.XElement("Data",
new System.Xml.Linq.XElement("IntValue", "123"),
new System.Xml.Linq.XElement("DblValue", "123.321"),
new System.Xml.Linq.XElement("StrValue", "ABCDEF")).ObjectToXml() }
}
},
// Moniker of development environment object with method implementation
tFore = new ForeId()
{
id = mb.id + "!" + FindObjectById(mb, assmId).k
}
};
// Execute method
var result = somClient.ForeExec(tExec);
return result;
}
See also: