首先,我不太了解.net或网络服务电话。如果以前已经回答过这个问题,我很抱歉。
我有以下代码片段,它遍历由SSIS中的执行SQL任务填充的数据集。我需要获取这些值并将它们发送到Web服务,以便Web服务可以执行任何操作。 我已经转到我可以迭代记录的部分,但我不确定如何引用Web服务调用中的列。这意味着,如果服务调用是xyz(val1,val2,val3,val4),我如何将val值与我创建的数据表相关联?
public void Main()
{
// TODO: Add your code here
var caseObj = Dts.Variables["User::QCase"].Value;
var serviceURI = Dts.Variables["User::WebServiceURI"].Value.ToString();
var oleDA = new OleDbDataAdapter();
var httpBinding = new BasicHttpBinding();
var dt = new DataTable();
string sMsg;
oleDA.Fill(dt, Dts.Variables["User::QCases"].Value);
foreach (DataRow row in dt.Rows)
foreach (DataColumn col in dt.Columns)
{
var caseProxy = new CaseService.CServicesProxyClient(httpBinding, new EndpointAddress(serviceURI));
sMsg = "";
sMsg = sMsg + col.ColumnName + ": " + (col.Ordinal).ToString() + vbCrLf;
MessageBox.Show(sMsg);
var results = caseProxy.SaveCaseStatusChange(dt, 0, false, null); //This is the service call which will push the values to the web service. dt is the data table.
}
/* if (results)
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}*/
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public object vbCrLf { get; set; }
}
}
我希望我已经提供了足够的细节,但如果没有,我将非常乐意提供。感谢您抽出宝贵时间阅读问题。
答案 0 :(得分:1)
除非我缺少一些细微差别,否则这很简单。你必须要记住的是,数组中的第一个元素将位于零位
您当前的方法,遍历Columns集合,可能对允许通用数据集的内容很有用,但我假设来自User::QCases
的数据始终是返回N列数据。深度,我不在乎,宽度我。
您需要查看您的Web服务方法,以查看它所期望的数据类型,并将您的数据从该行强制转换为该类型。此外,您需要处理NULL(或不处理,基于您的数据),但.NET原始类型不允许NULL值。你可以&#34;作弊&#34;通过使用?类型,但这使得它比我可以自由类型的响应更长。
foreach (DataRow row in dt.Rows)
{
// row is going to contain the current row worth of data
// All you need to do is access the values.
var results = caseProxy.SaveCaseStatusChange(row[0].ToString(), row[1].ToString(), row[2].ToString(), row[3].ToString());
}
有一些机制可以按名称而不是它们的顺序位置来寻址列,这样就可以随时访问Id
列,无论它是第一列还是最后一列。