1

I have an ASMX web service that I need to utilise as part of a piece of work. I am calling this service via an ASPX page to create new entities on a 3rd party system. I have no access to the underlying code to that service, its simply to allow me to communicate with another system.

Im having trouble finding out if I am calling the service correctly and I wonder if anyone could offer some advice.

I have installed the ASMX page and that has given me a class 'ConfirmConnector' which I call the BeginProcessOperations method. I want to wait on that to return and then parse te results. The results should be in XML which I then step through to get the data I am after.

The trouble is that sometimes this process just dies on me, i.e. when I call my 'EndProcessOperations' method then nothing happens. I dont get an error, nothing - my code just dies and the method returns'

My calling code is:

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

My handler code is :

 /*
 * 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);

Can anyone advise if I am handling this code in the correct way and does anyone have any idea why my code randomly bombs after this line in the handler :

XmlNode root =  conn.EndProcessOperations(result);

Thanks for your help, Paul

Paul Lyons
  • 11
  • 2
  • 5

1 Answers1

0

thanks for looking, but I solved my problem. The issue appeared to be related to my callback operation.

I changed the code to call my begin & end methods in the same block of code and I havent had an issue since then.

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

Thanks

Paul

Paul Lyons
  • 11
  • 2
  • 5