Я сейчас пытаюсь использовать SSI для потребления данных из API, который я нашел в Интернете (ссылка API). Я попытался выполнить следующие шаги, найденные в этом сообщении в блоге (блог Денниса и Джима < /p>
Однако я продолжаю получать эту ошибку: < /p>
[Ошибка получения данных от веб -сервиса !!] Ошибка:
system.missingmethodexcept /> ystem.web.script.serialization.objectConverter.convertdictionAryToObject(IdicationAry`2
Dictionary, тип, javascriptSerializ /> ystem.web.script.serialization.objectconverter.convertobjecttotytonental(object
o, тип типа, JavascriptSerializ /> system.web.script.serialization.javascriptserializer.deserialize(javascriptserializer
Serializer, ввод строки, тип типа, Int32 Devinlimit) at
system.web.script.serialization.javascriptserializ Scriptmain.getWebServiceResult (string wurl) < /p>
< /blockquote>
Вот копия письменного кода, который я пробовал: < /p>
Код: Выделить всё
public override void CreateNewOutputRows()
{
//Get SSIS Variables
//int population = this.Variables.MEASURE;
//set Webservice URL
string wUrl = "https://datausa.io/api/data?drilldowns=Nation&measures=Population";
try
{
//call drilldowns to obtain Nation's population
DrillDowns[] populationOutput = GetWebServiceResult(wUrl);
//For each year output population
foreach (var value in populationOutput)
{
Output0Buffer.AddRow();
Output0Buffer.Population = value.Population;
Output0Buffer.Year= value.Year;
Output0Buffer.Nation = value.Nation;
}
}
catch (Exception ex)
{
FailComponent(ex.ToString());
}
}
private DrillDowns[] GetWebServiceResult(string wUrl)
{
HttpWebRequest httpWReq= (HttpWebRequest)WebRequest.Create(wUrl);
HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
DrillDowns[] jsonResponse = null;
try
{
//Test the connection
if (httpWResp.StatusCode == HttpStatusCode.OK)
{
Stream responseStream= httpWResp.GetResponseStream();
string jsonString = null;
//Set jsonString using a stream reader
using (StreamReader reader = new StreamReader(responseStream))
{
jsonString = reader.ReadToEnd().Replace("\\", "");
reader.Close();
}
//Deserializing the Json
JavaScriptSerializer sr = new JavaScriptSerializer();
//JSON string comes with a leading and trailing " tthat needs to be removed for parsing to work correctly
jsonResponse = sr.Deserialize(jsonString);
}
//Output connection error message
else
{
FailComponent(httpWResp.StatusCode.ToString());
}
}
//Output JSON parsing error
catch (Exception ex)
{
FailComponent(ex.ToString());
}
return jsonResponse;
}
private void FailComponent(string errorMsg)
{
bool fail = false;
IDTSComponentMetaData100 compMetadata = this.ComponentMetaData;
compMetadata.FireError(1, "Error getting data from Webservice!!",
errorMsg, "", 0, out fail);
}
//Class to hold our drillDowns
public class DrillDowns
{
public string Nation { get; set; }
public string Year { get; set; }
public int Population { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/755 ... ined-for-t