none
WCF Failing when Return value not 0 RRS feed

  • Question

  • Hi all;

      I am trying to write a WPF application that sends an agent to multiple machines in my domain,  and uses a WCF service hosted in the application to store the status of the returned results.  The WPF application also calls the service to get the results returned by the Agents and display the status in a datagrid.

    The WCF service appears to be working properly,  as many of the functions it exposes work properly.  The problem function in question returns a dictionary<string,JobStatusRow> where the string is the name of the machine the agent is running on, and JobStatusRow is defined in a DataContract.

    To begin with, here is the code from my contract:

            public Dictionary<string, JobStatusRow> DatagridSource()
            {
                //For datarows we need to build a dictionary with all servers in the active list,  and a list of the tasks they have.  For each server,  we also need to determine the last time they connected,  and set the connection details.
                DatagridLock.TryEnterWriteLock(3000);  //Make a copy of the Dictionary using a lock to prevent conflicts.  Close it immediately when finished.
                var AllJobs = _DatagridSource;
                Dictionary<string,JobStatusRow> ToReturn = new Dictionary<string,JobStatusRow>(); //THis is a list of all Servers we have touched in this session
                DatagridLock.ExitWriteLock();
    
                ConnectedClientLock.TryEnterReadLock(3000);
                var localconnected = _ConnectedClients; // This is a list of Agents that are connected to the service
                ConnectedClientLock.ExitReadLock();
    
                ServersInScopeLock.TryEnterReadLock(3000);
                var LSI = _ServersInScope;  // This contains a list of the servers we are actively working with at the moment.
                ServersInScopeLock.ExitReadLock();
    
    
                //Update the connection status of each server.
                foreach (string hostname in LSI)
                {
                    if (AllJobs.Keys.Contains(hostname))
                    {
                        ToReturn.Add(hostname,AllJobs[hostname]);
                    }
    
                    //Next, we need to update the connection status of the server associated with the task.
    
                        if (ToReturn.Keys.Contains(hostname))
                        {
                            if (localconnected.Keys.Contains(hostname))
                            {
                                ToReturn[hostname].lastconnected = localconnected[hostname].ToString();
                                ToReturn[hostname].AgentStatusLED = SImages.GetLEDWPF("Green");  //The Datarow contains an image object with an LED indicator for visual status.
                            }
                            else
                            {
                                ToReturn[hostname].AgentStatusLED = SImages.GetLEDWPF("Red");
                            }
                        }
                }
                return ToReturn;
            }

    Now,  this is the code that calls that function

            private void UpdateJobDataGrid_Tick(object sender, EventArgs e)
            {
                var ConsoleService = ConsoleContract.CreateChannel(new EndpointAddress(MyEndpoint));
                var boggart = ConsoleService.GetThreadData(); //Just a call to make sure we can talk to the service.  Returns the threadID of the console process.
                Dictionary<string,TaskConsoleWCFService.JobStatusRow> alldatarows = ConsoleService.DatagridSource();
            }

    The code above executes every 5 seconds to keep the datagrid up to date.  It works as long as the return value has a count of 0, which is as long as I have no servers it is managing.

                       

    When I call the function that adds a list of servers to the Service, the Return value should now contain a dictionary containing the name of the Agent server and  of datarows showing the Task list and status of those servers. As near as I can tell,  everything looks good at the time the Return happens:

                      

    It is at this point that my program croaks, and I can't figure out why.  It takes about 4 seconds from the time I continue from the return to the crash.

                     

    So,  I can tell from the fact that "boggart" was set,  that I was able to call the service and get a response.  Communications seem to be good.  I can see that the return values are the correct type and there is no error in the contract code.   The timeout value is obviously a red herring, because we did not get anywhere near a 1 minute timeout.  There is no code between the call and the return that I can debug.    I get the same error when I try to use the WCF Test Client against the WCF service,  so I don't think it is my connection parameters.

    Help!!!!


    Thursday, January 2, 2014 4:38 PM

Answers

  • Oh, joy.   It looks like this just gets more and more fun.  Appears that the error is build in to the WPF image object,  so I am basically screwed as WPF has a built in exception,  and WCF wont allow me to pass  the WPF image object with an exception.    Arrrggghhh! Will need to figure out how to implement the fix Andrej mentions. 

    Found this information:

    I had the similar problem - the same exception in the BitmapFrame.Create method.

    Than I have checked the .net source code for  BitmapFrame.Create method and found the following:

                try
                {
                    metadata = source.Metadata as BitmapMetadata;
                }
                catch (System.NotSupportedException)
                {
                    //do not throw not support exception
                    //just pass null
                }

    So the exception is actually caught by the .net framework, but if you have break on exceptions turned on in VS, it is hard to know that the code can continue.

    This means there is no real exception.

    But anyway in my oppenion the code is not well written.
    It is quite annoying to debug such code - I have been processing lots of bitmaps and after several click on continue button (after break on exception) I have changed the code to copy the raw bytes from the BitmapImage into the GID+ Bitmap and use its Save method :)

    I hope the WPF team will read this and improve the code.

    Andrej

    Hi,

    If you question is more related to the WPF, then please try to post your question to the WPF forums, then the WPF experts can help you to find the solution.
    #WPF Forums:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 3, 2014 6:05 AM
    Moderator

All replies

  • Further testing using WCF Test Client also shows the same symptoms.  Everything works. All functions work.  It only fails when I actually have values in the returned dictionary. 
    Thursday, January 2, 2014 4:51 PM
  • Harumph. Digging in deeper I was able to get the code to execute properly by removing the images. The problem appears to be that the DataRow contains an Image. It appears that having the image in the returned datarow broke things.  This did not show up until I dug down, and the debugger never said anything:

                   

     Guess this isn't a WCF problem after all.  Will start looking more at how images are handled. 
    • Marked as answer by Stiv Ostenberg Thursday, January 2, 2014 5:12 PM
    • Unmarked as answer by Stiv Ostenberg Thursday, January 2, 2014 5:23 PM
    Thursday, January 2, 2014 5:12 PM
  • Oh, joy.   It looks like this just gets more and more fun.  Appears that the error is build in to the WPF image object,  so I am basically screwed as WPF has a built in exception,  and WCF wont allow me to pass  the WPF image object with an exception.    Arrrggghhh! Will need to figure out how to implement the fix Andrej mentions. 

    Found this information:

    I had the similar problem - the same exception in the BitmapFrame.Create method.

    Than I have checked the .net source code for  BitmapFrame.Create method and found the following:

                try
                {
                    metadata = source.Metadata as BitmapMetadata;
                }
                catch (System.NotSupportedException)
                {
                    //do not throw not support exception
                    //just pass null
                }

    So the exception is actually caught by the .net framework, but if you have break on exceptions turned on in VS, it is hard to know that the code can continue.

    This means there is no real exception.

    But anyway in my oppenion the code is not well written.
    It is quite annoying to debug such code - I have been processing lots of bitmaps and after several click on continue button (after break on exception) I have changed the code to copy the raw bytes from the BitmapImage into the GID+ Bitmap and use its Save method :)

    I hope the WPF team will read this and improve the code.

    Andrej

    Thursday, January 2, 2014 5:33 PM
  • Oh, joy.   It looks like this just gets more and more fun.  Appears that the error is build in to the WPF image object,  so I am basically screwed as WPF has a built in exception,  and WCF wont allow me to pass  the WPF image object with an exception.    Arrrggghhh! Will need to figure out how to implement the fix Andrej mentions. 

    Found this information:

    I had the similar problem - the same exception in the BitmapFrame.Create method.

    Than I have checked the .net source code for  BitmapFrame.Create method and found the following:

                try
                {
                    metadata = source.Metadata as BitmapMetadata;
                }
                catch (System.NotSupportedException)
                {
                    //do not throw not support exception
                    //just pass null
                }

    So the exception is actually caught by the .net framework, but if you have break on exceptions turned on in VS, it is hard to know that the code can continue.

    This means there is no real exception.

    But anyway in my oppenion the code is not well written.
    It is quite annoying to debug such code - I have been processing lots of bitmaps and after several click on continue button (after break on exception) I have changed the code to copy the raw bytes from the BitmapImage into the GID+ Bitmap and use its Save method :)

    I hope the WPF team will read this and improve the code.

    Andrej

    Hi,

    If you question is more related to the WPF, then please try to post your question to the WPF forums, then the WPF experts can help you to find the solution.
    #WPF Forums:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 3, 2014 6:05 AM
    Moderator