2012-11-11 50 views
1

我有一個ASMX Web服務,我需要使用它作爲一項工作的一部分。我通過ASPX頁面調用此服務以在第三方系統上創建新實體。我無法訪問該服務的底層代碼,只是爲了讓我能夠與另一個系統通信。調用C#ASMX Web服務

很難找到了,如果我呼籲正確的服務,我不知道是否有人能提供一些建議林。

我已經安裝了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); 

感謝您的幫助, 保羅

+0

歡迎計算器!通常你不必包含「謝謝」等等或你的名字。我們知道你非常感謝你的幫助,所以這是隱含的,你的名字已經在問題的左下角。 :) – Patrick

+0

哎呀 - 對不起,我沒有意識到我忘了它。我重新提出了大約5次的問題,並且必須複製它。 –

+0

在此先感謝所有回覆 –

回答

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

感謝

保羅