简体   繁体   English

异步 Web 服务调用

[英]Asynchronous Web Service Calls

I have written this code which accesses the Delete method on Web Service x, I will be creating wrappers for each of the methods but I am hitting a blocker on something probably very simple.我已经编写了这段代码来访问 Web 服务 x 上的 Delete 方法,我将为每个方法创建包装器,但我在一些可能非常简单的事情上遇到了障碍。

My code consists of three methods:我的代码由三种方法组成:

  • One to make the delete call, this simply passes the params to an Async method.一个进行删除调用,这只是将参数传递给 Async 方法。
  • The second is the event handler.第二个是事件处理程序。
  • The third processes the results into a data table第三个将结果处理成数据表

Here is my current code:这是我当前的代码:

public void Delete(string[] Identifiers, string ObjectType)
{
    service.deleteAsync(ObjectType, Identifiers);
    service.deleteCompleted += new deleteCompletedEventHandler(service_deleteCompleted);
}

void service_deleteCompleted(object sender, deleteCompletedEventArgs e)
{
    StoreResults(e.Result);
    if (resultsTable.Rows.Count == totalRecords)
    {
        CSVFile myFile = new CSVFile(",", true);
        myFile.Save(resultsTable, outputPath);
        Console.WriteLine("Tasks completed");
    }
}

public void StoreResults(DeleteResult[] ResultSet)
{
    if (resultsTable.Columns.Count < 1)
    {
        resultsTable.Columns.Add("ID");
        resultsTable.Columns.Add("Errors");
        resultsTable.Columns.Add("Success");
    }

    foreach (DeleteResult r in ResultSet)
    {
        StringBuilder errors = new StringBuilder();
        object[] newRow = new object[3];

        newRow[0] = r.id;
        if (r.errors != null)
        {
            newRow[1] = errors[0].ToString();
        }
        else
            newRow[1] = "No Errors to Report";

        newRow[2] = r.success.ToString();

        resultsTable.Rows.Add(newRow);
    }
}

A restriction of the webservice is that I can only pass 50 ID's per call, so I have some background code which manages the chunking of source data, what I need to acheive now is to store all of those results in a data table and pass it back.网络服务的一个限制是我每次调用只能传递 50 个 ID,所以我有一些管理源数据分块的后台代码,我现在需要实现的是将所有这些结果存储在数据表中并传递它背部。

You have to subscribe first:您必须先订阅:

public void Delete(string[] Identifiers, string ObjectType)
{
    service.deleteCompleted += service_deleteCompleted;
    service.deleteAsync(ObjectType, Identifiers);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM