Several bugs in the MantisConnect API

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
MagicBuzz
Posts: 3
Joined: 02 May 2011, 11:43

Several bugs in the MantisConnect API

Post by MagicBuzz »

Hello,

I'm trying to write a simplified .NET client for the Mantis application.

For this, I use C# (Visual Studio 2010) and I try to call the MantisConnect Webservices.

I don't want to use the DLL provided by the FutureWare team : .NET has native support of web services, so I want it to call it natively.

I already found 2 errors in the API, but I didn't fixed it.

1/ In the mc_projects_get_user_accessible() method, when the credentials are wrong, the the webservice returns a malformed XML response :
Exception Message : The server returned an invalid SOAP error. For more information, please consult the InnerException Message.
InnerException Message : The element 'faultstring' with '' name space cann't be found. Line 6, Position 117. The real error message isn't readable from the C# program.

2/ In the mc_issue_add method, it the category is unspecified while it's mandatory in the server's configuration, then the provided error message is encoded in iso-8859-1 while the webservice response is utf-8. Again, the exception isn't readable from the C# program.

Here is the code for the 1st issue :

Code: Select all

            FrmLogin frmLogin = new FrmLogin();

        login:
            if (frmLogin.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    _client = new MantisConnect.MantisConnectPortTypeClient();
                    _client.ClientCredentials.UserName.UserName = frmLogin.GetLogin();
                    _client.ClientCredentials.UserName.Password = frmLogin.GetPassword();
                    _client.Open();
/* Here is the error when login/pass is invalid */
                    MantisConnect.ProjectData[] projects = _client.mc_projects_get_user_accessible(_client.ClientCredentials.UserName.UserName, _client.ClientCredentials.UserName.Password);
                    if (projects.Length == 0)
                    {
                        MessageBox.Show(this, "Le login ou mot de passe ne vous permet pas de vous connecter à un projet.", "Login incorrect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        goto login; /* Well, ok, "goto" is hell, but sometimes... it's still usefull ;) */
                    }
                    this._projects = projects;
                    projetToolStripMenuItem.DropDownItems.Clear();

                    foreach (MantisConnect.ProjectData project in projects)
                    {
                        projetToolStripMenuItem.DropDownItems.Add(project.name, null, project_Change);
                    }

                    if (projects.Length > 0)
                    {
                        project_Change(projetToolStripMenuItem.DropDownItems[0], new EventArgs());
                    }
                    return;
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    while (ex != null)
                    {
                        sb.AppendLine(ex.Message);
                        foreach (KeyValuePair<object, object> p in ex.Data)
                        {
                            sb.AppendFormat("{0} = {1}\n", p.Key, p.Value);
                        }
                        sb.AppendLine();
                        ex = ex.InnerException;
                    }
                    MessageBox.Show(sb.ToString());
                    goto login;
                }
            }
Code for 2nd issue :

Code: Select all

            if (_issue == null)
            {
/* Will produce unreadable exception if newIssueData.category is empty */
                _client.mc_issue_add(_client.ClientCredentials.UserName.UserName, _client.ClientCredentials.UserName.Password, newIssueData);
            }
            else
            {
                _client.mc_issue_update(_client.ClientCredentials.UserName.UserName, _client.ClientCredentials.UserName.Password, newIssueData.id, newIssueData);
            }
Post Reply