Working with Objects in JSON Format

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:

Method

The C# example uses the FindObjectById function, which code is given in the Getting Object Description by Its Identifier example.

SOAP request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ForeExec xmlns="http://www.fsight.ru/PP.SOM.Som">
<tFore xmlns="">
  <id>AHHCPKBHELFGGOAEJJPPPODMMPIBEDEEALGKJDIIBMIMFFJM!M!7360</id>
  </tFore>
<tArg xmlns="">
  <methodName>WorkWithJson</methodName>
<args>
<it>
  <k>1</k>
<jsonValue>
<Data>
  <IntValue>123</IntValue>
  <DblValue>123.321</DblValue>
  <StrValue>ABCDEF</StrValue>
  </Data>
  </jsonValue>
  </it>
  </args>
  </tArg>
  </ForeExec>
  </s:Body>
  </s:Envelope>

SOAP response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
  <ForeExecResult xmlns="http://www.fsight.ru/PP.SOM.Som" xmlns:q1="http://www.fsight.ru/PP.SOM.Som" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">{"json":{"ExecResult":true,"ExecDay":"31.07.2025 00:00:00"}}"</ForeExecResult>
  </soapenv:Body>
  </soapenv:Envelope>

JSON request:

{
"ForeExec" :
{
"tFore" :
{
"id" : "AHHCPKBHELFGGOAEJJPPPODMMPIBEDEEALGKJDIIBMIMFFJM!M!7360"
},
"tArg" :
{
"methodName" : "WorkWithJson",
"args" :
{
"it" :
{
"k" : "1",
"jsonValue" :
{
"Data" :
{
"IntValue" : "123",
"DblValue" : "123.321",
"StrValue" : "ABCDEF"
}
}
}
}
}
}
}

JSON response:

{
"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:

ForeExec: Operation