General exception through webservices

I am integrating with MS Dynamics GP WebServices from C # and I'm not sure how to handle the exception.

If I make GetCustomer with an unconvincing identifier, the web services return a "general" SoapException to me and the message "Business object not found". Therefore, the only way to make sure that this is an invalid identifier, and not some other error, is to analyze the error message, I find this solution extremely fragile. My version of GP is English, it will be French on the client site, and I have no idea what language web service the message will be in. I am thinking of catching it by parsing the message and throwing a more meaningful type of error.

Do you see the best option?

+3
source share
5 answers

Unfortunately, both the eConnect API and GP Web Services return common errors, just be glad you don’t need to parse eConnect.

Well, errors are usually static, so you can create parsers for them. Creating custom exceptions is certainly a good way to do this with this type of web service.

+1
source

I have a blog post that details how I overcame this issue in WCF (although, as you can see, I don't mind parsing the error message to get the info). Here is his meat:

catch (FaultException soapEx)
{
    MessageFault mf = soapEx.CreateMessageFault();
    if (mf.HasDetail)
    {
        XmlDictionaryReader reader = mf.GetReaderAtDetailContents();
        Guid g = reader.ReadContentAsGuid();
    }
}

Once you have a GUID, you can use it to query the GP web service for detailed error information.

+1
source

WebService?

SoapExceptions , , .

" " WebService, .

//Example
enum ErrorCodes
{
  BusinessObjectNotFound = 1000,
  AnotherPossibleError = 1002
}

try
{
//Code
}
Catch(BusinessObjectNotFoundException bex)
{
  throw new SoapException(ErrorCodes.BusinessObjectNotFound);
  //Or maybe...
  //throw new SoapException(((int)ErrorCodes.BusinessObjectNotFound).ToString());
}
0
source

For information for people interested in topics, Jacob Profitt's answer looks like a way to go. here is the operator from the Dynamics GP documentation:

catch(SoapException soapErr)
{
    // If a validation exception occurred, the logid will be in a child node
    if(soapErr.Detail.HasChildNodes == true)
    {
        // Create a guid for the logid value in the soap exception
        Guid guid = new Guid(soapErr.Detail.InnerText);

        // Get the validation result object
        validationResult = wsDynamicsGP.GetLoggedValidationResultByKey(guid, context);

        // Display the number of validation exceptions
        MessageBox.Show("Number of validation exceptions: " +
        validationResult.Errors.Length.ToString());
    }

}

But in the case where I cited: GetCustomer with an impossible identifier, the string "soapErr.Detail.HasChildNodes" is incorrect, so it fails.

Web services seem full of ridiculous behavior, it will take longer than I expected: (.

0
source

I'm starting to hate the GP. It may be a "bad form", but here is what I did:

try
{
    // query service for object by key
}
catch (System.ServiceModel.FaultException e)
{
    if (e.Message == "Business object not found.")
    {
        // create new object
    }
    else
    {
        // log the exception appropriately
    }
}
0
source

All Articles