Saltar al contenido

Ejemplo de Secuencia de Comandos: Devolver un Campo Como XML

Este secuencia de comandos de ejemplo de complemento devolverá un campo en su objeto de datos a través del extremo REST como XML, haciéndolo utilizable por otras aplicaciones y plataformas. Consulte las Notas de configuración para desplegar este complemento en Vinyl.

Secuencia de Comandos de Ejemplo

#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
/**
 The format of the json produced by Vinyl is:
 {
     items: [
       {
           "field1": "value",
           "field2": "value",
           "field3": "value",
           ...
       }
       ...
     ]
 }

 This plugin is grabbing the FIRST item returned (["items"][0])

 We then look for a particular field containing xml - in this case "xmlCode"

 We then return this as the xml content - discarding the rest of the message
**/
// Read the response content
var message = await Response.Content.ReadAsStringAsync();
var jobject = JObject.Parse(message);
// This is likely always the same - the first item returned
var item = jobject["items"][0];
// Change xmlCode to match the name of the field in your object:
var xmlContent = item["xmlCode"].ToString();
// Return just the xmlContent
Response.Content = new StringContent(xmlContent, null, "application/xml");

Notas de Configuración

  1. Al configurar el complemento en Vinyl, utilice los siguientes valores:

    • Nombre: ReturnXmlFromJson
    • Descripción: Seleccione xml devuelto desde json y devuélvalo solo como xml
    • Propósito: Respuesta de descanso
  2. Al configurar XMP Extremo en Vinyl, haga clic en Configuración de Edge Case y establezca el valor Respuesta del complemento Extremo en ReturnXmlFromJson

  3. Al configurar el servicio web API REST, establezca el valor Tipo de contenido de solicitud en JSON y Tipo de contenido de respuesta en XML.