【问题标题】:Calling C# ASMX Web Service调用 C# ASMX Web 服务
【发布时间】:2012-10-31 05:28:20
【问题描述】:

我有一个 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);

感谢您的帮助, 保罗

【问题讨论】:

  • 欢迎来到 Stackoverflow!您通常不必包含“谢谢”等或您的名字。我们知道您很感激您的帮助,所以它是含蓄的,您的名字已经在问题的左下角。 :)
  • 哎呀 - 对不起,我没有意识到我忘记了。我把这个问题重新措辞了大约 5 次,肯定是抄了一遍。
  • 提前感谢大家的回复
  • 您能否更详细地说明您在该行所说的代码炸弹是什么意思?
  • 我的意思是该行之后的所有代码似乎都没有执行。我的代码移至下一个方法 - 但该方法中没有其他内容。

标签: c# asmx iasyncresult waithandle


【解决方案1】:

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

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

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();
}

谢谢

保罗

【讨论】:

    猜你喜欢
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    相关资源
    最近更新 更多