-1

我必须使用回调(异步)、结果..等调用 api(SOAP)。我必须使用的方法:

public IAsyncResult BeginInsertIncident(
    string userName, string password, string MsgId, string ThirdPartyRef,
    string Type, string EmployeeId, string ShortDescription, string Details,
    string Category, string Service, string OwnerGrp, string OwnerRep,
    string SecondLevelGrp, string SecondLevelRep, string ThirdLevelGrp,
    string ThirdLevelRep, string Impact, string Urgency, string Priority,
    string Source, string Status, string State, string Solution,
    string ResolvedDate, string Cause, string Approved, AsyncCallback callback,
    object asyncState);

EndInsertIncident(IAsyncResult asyncResult, out string msg);

EndInsertIncident 关闭票证系统中的请求,如果票证正确完成,则给出结果。

现状:

server3.ILTISAPI api = new servert3.ILTISAPI();
api.BeginInsertIncident(username, "", msg_id, "", "", windows_user,
    "BISS - Software Deployment", "", "", "NOT DETERMINED", "", "", "", "", "",
    "", "5 - BAU", "3 - BAU", "", "Interface", "", "", "", "", "", "", null,
    null);

那么,现在,我如何实现回调函数?api“InsertIncidentCompleted”的状态已经为空,因为我认为我不调用 EndInsertIncident。

我是 C# 新手,需要一些帮助。

4

1 回答 1

0

AsyncCallback是一个委托,它返回 void 并接受一个类型的参数IAsyncResult

因此,使用此签名创建一个方法并将其作为倒数第二个参数传递:

private void InsertIncidentCallback(IAsyncResult result)
{
    // do something and then:
    string message;
    api.EndInsertIncident(result, out message);
}

像这样传递它:

api.BeginInsertIncident(username, "", msg_id, "", "", windows_user,
    "BISS - Software Deployment", "", "", "NOT DETERMINED", "", "", "", "", "",
    "", "5 - BAU", "3 - BAU", "", "Interface", "", "", "", "", "", "",
    InsertIncidentCallback, null);

如果您不能创建api类的成员变量并希望将其传递给回调,则必须执行以下操作:

private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result)
{
    // do something and then:
    string message;
    api.EndInsertIncident(result, out message);
}

为了能够将其作为回调传递,您必须使用委托:

api.BeginInsertIncident(..., r => InsertIncidentCallback(api, r), null);
于 2013-02-26T09:50:47.900 回答