Netsuite:通过API下载XML响应

时间:2015-08-03 17:44:34

标签: c# xml netsuite

背景:C#和NetSuite相对较新。

给出一个小的netsuite方法(通过SuiteTalk),例如:

private void getInvoice()
{
    RecordRef invoiceRef = new RecordRef
    {
        internalId = "111111",
        type = RecordType.invoice,
        typeSpecified = true
    };

    ReadResponse readResponse = _service.get(invoiceRef);

}//eof

我如何将整个readResponse作为文件获取?它是前端的XML文件...我可以将其下载/读取到此脚本末尾的文件中吗?我不知道它在这里是否被视为流,这会使它变得更容易将其变成文件。

1 个答案:

答案 0 :(得分:0)

在您的示例中,将向NetSuite发出请求,并且响应将作为ReadResponse类加载到“readResponse”变量中。然后,您需要将返回的记录转换为发票:

Invoice invoiceRecord = (Invoice)readResponse.record;

如果要将响应写入文件,可以执行以下操作:

        ReadResponse readResponse = _service.get(invoiceRef);
        FileStream fs = System.IO.File.Create("response.xml");
        XmlSerializer writer = new XmlSerializer(typeof(ReadResponse));
        writer.Serialize(fs, readResponse);
        fs.Close();