PostExecute()输出缓冲区Foreach行

时间:2017-05-18 02:48:59

标签: c# ssis script-component

我在SSIS的脚本组件中有以下代码。

我正在尝试反序列化JSON输出并将响应输出到数据库。

反序列化部分正在返回响应。

output checkpoint

但是我得到一个未设置为实例的" Object引用 一个物体。" OutputBuffer.AddRow();

上的错误

enter image description here

我绕圈子走了。我做错了什么?

public class ScriptMain : UserComponent
{

   public override void PostExecute()
    {
        base.PostExecute();

        string vOpportunityURL = Variables.pardotopportunityurl;
        System.Windows.Forms.MessageBox.Show(vOpportunityURL);

        int vMaxOpportunityId = Variables.pardotopportunitymaxid;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vMaxOpportunityId));

        int vProcessedRecordCount = Variables.pardotrecordcnt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessedRecordCount));

        var vProcessDate = Variables.pardotprocessdt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessDate));

        RootObject oppOutputResponse = GetWebServiceResult(vOpportunityURL);

        foreach (Opportunity op in oppOutputResponse.result.opportunity)
        {

            OpportunityDataBuffer.AddRow();
            OpportunityDataBuffer.ID = op.id;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.id));
            OpportunityDataBuffer.Name = op.name;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.name));

        }


    }


    private RootObject GetWebServiceResult(string vOpportunityURL)
    { 
        // Create API WEeb Service Request

        HttpWebRequest opportunityFullDataReq = (HttpWebRequest)WebRequest.Create(vOpportunityURL);

        var opportunityDataPostStr = "user_key=";
            opportunityDataPostStr += Variables.pardotauthusrkey;
            opportunityDataPostStr += "&api_key=";
            opportunityDataPostStr += Variables.pardotapikey;
            opportunityDataPostStr += "&output=full";
            opportunityDataPostStr += "&format=json";
            opportunityDataPostStr += "&sort_by=id";
            opportunityDataPostStr += "&sort_order=ascending";
            opportunityDataPostStr += "&id_greater_than=";
            opportunityDataPostStr += Variables.pardotopportunitymaxid;

            System.Windows.Forms.MessageBox.Show(Convert.ToString(opportunityDataPostStr));
            System.Windows.Forms.MessageBox.Show(vOpportunityURL + Convert.ToString(opportunityDataPostStr));

        var opportunityPostStream = Encoding.ASCII.GetBytes(opportunityDataPostStr);

        opportunityFullDataReq.Method = "POST";
        opportunityFullDataReq.ContentType = "application/x-www-form-urlencoded";
        opportunityFullDataReq.ContentLength = opportunityPostStream.Length;

        using(var opportunityStream = opportunityFullDataReq.GetRequestStream())
        {
            opportunityStream.Write(opportunityPostStream, 0, opportunityPostStream.Length);
        }

        // Capture Web Service Respose

        HttpWebResponse opportunityFullDataResponse = (HttpWebResponse)opportunityFullDataReq.GetResponse();

        RootObject opportunityWSResponse = null;

        Stream opportunityJsonStream = opportunityFullDataResponse.GetResponseStream();
        string wsResponseString = null;

        using (StreamReader wsResponseReader = new StreamReader(opportunityJsonStream))
        {
            wsResponseString = wsResponseReader.ReadToEnd();
            wsResponseReader.Close();
        }

        JavaScriptSerializer wsResponseJson = new JavaScriptSerializer();

        //var serialJsonResponseString = wsResponseJson.Serialize(wsResponseString);
        System.Windows.Forms.MessageBox.Show(wsResponseString.ToString());

        opportunityWSResponse = wsResponseJson.Deserialize<RootObject>(wsResponseString);

        return opportunityWSResponse;
   }

1 个答案:

答案 0 :(得分:1)

PostExecute 中不存在输出缓冲区。

在调用方法向缓冲区添加内容之前,您可以检查最后一行是否已通过缓冲区。

这里有类似的问题:Can I add rows to Output Buffer in SSIS Script Component in PostExecute?