1

我有一个 ASMX Web 服务,我需要在工作中使用它。我通过 ASPX 页面调用此服务以在第 3 方系统上创建新实体。我无法访问该服务的底层代码,它只是为了让我与另一个系统进行通信。

我无法确定我是否正确调用了该服务,我想知道是否有人可以提供一些建议。

我已经安装了 ASMX 页面,这给了我一个名为“ConfirmConnector”的类,我称之为 BeginProcessOperations 方法。我想等待它返回然后解析结果。结果应该是 XML 格式,然后我会逐步获取我想要的数据。

问题是有时这个过程会在我身上消失,即当我调用我的“EndProcessOperations”方法时,什么也没有发生。我没有收到错误,什么都没有——我的代码死了,方法返回了

我的调用代码是:

private void sendConfirmRequest(XmlManipulator requestXML)
{
    file.WriteLine("Sending CONFIRM Request!");
    AsyncCallback callBack = new AsyncCallback(processConfirmXML); // assign the callback method for this call

    IAsyncResult r = conn.BeginProcessOperations(requestXML, callBack, AsyncState);
    System.Threading.WaitHandle[] waitHandle = { r.AsyncWaitHandle }; // set up a wait handle so that the process doesnt automatically return to the ASPX page
    System.Threading.WaitHandle.WaitAll(waitHandle, -1);
}

我的处理程序代码是:

 /*
 * Process the response XML from the CONFIRM Connector
 */
private static void processConfirmXML(IAsyncResult result)
{
    try
    {
        file.WriteLine("Received Response from CONFIRM!");
        if(result == null)
        {
            file.WriteLine("RESPONSE is null!!");
        }
        if(conn == null)
        {
            file.WriteLine("conn is null!!");
        }
        file.WriteLine("Is Completed : " + result.IsCompleted);

        XmlNode root =  conn.EndProcessOperations(result);
        file.WriteLine("got return XML");
        //writeXMLToFile("C:/response.xml",root.InnerXml);
        file.WriteLine(root.InnerXml);

谁能建议我是否以正确的方式处理此代码,并且有人知道为什么我的代码在处理程序中的此行之后随机炸弹:

XmlNode root =  conn.EndProcessOperations(result);

谢谢你的帮助,保罗

4

1 回答 1

0

感谢您的关注,但我解决了我的问题。该问题似乎与我的回调操作有关。

我更改了代码以在同一代码块中调用我的开始和结束方法,从那时起我就没有遇到过问题。

private void sendConfirmRequest(XmlManipulator requestXML)
{
    //ConfirmConnector conn = new ConfirmConnector();
    file.WriteLine("Sending CONFIRM Request!");
    //AsyncCallback callBack = new AsyncCallback(processConfirmXML); // assign the callback method for this call

    //IAsyncResult r = conn.BeginProcessOperations(requestXML, callBack, AsyncState);
    //System.Threading.WaitHandle[] waitHandle = { r.AsyncWaitHandle }; // set up a wait handle so that the process doesnt automatically return to the ASPX page
    //System.Threading.WaitHandle.WaitAll(waitHandle, -1);

    file.WriteLine("Calling BeginProcessOperations");
    IAsyncResult result = conn.BeginProcessOperations(requestXML, null, null);
    // Wait for the WaitHandle to become signaled.
    result.AsyncWaitHandle.WaitOne();
    file.WriteLine("Calling EndProcessOperations");
    XmlNode root = conn.EndProcessOperations(result);
    processConfirmXML(root);

    file.WriteLine("got return XML");
    //writeXMLToFile("C:/response.xml",root.InnerXml);
    file.WriteLine(root.InnerXml);

    // Close the wait handle.
    result.AsyncWaitHandle.Close();
}

谢谢

保罗

于 2012-11-12T19:59:02.067 回答