Exception when generating a "Join Group" request

Jul 24, 2013 at 10:54 AM
Hi,

I'm customising the Join Groups page of the FIM portal to add a comments field to it. I have installed the Microsoft.ResourceManagement.Client and Microsoft.ResrouceManagement.ObjectModel assemblies and have changed the aspx pages to show my version of the Join Groups page - so far so good.

Now, when I click the submit button, a request isn't even generated. Instead, I get an exception of "The request message contains errors that prevent processing the request". From the server logs, I see this:
Requestor: urn:uuid:7fb2b853-24f0-4498-9534-4e10589723c4
Correlation Identifier: cbd8e078-19c3-4a79-9dd8-bd041504cda8
Microsoft.ResourceManagement: Microsoft.ResourceManagement.WebServices.Exceptions.InvalidRepresentationException: ChangeOperationIsNotSupported
at Microsoft.ResourceManagement.WebServices.XPathLevel1DialectParser.ParseXPathFragmentType(FragmentType xpathFragment)
at Microsoft.ResourceManagement.WebServices.XPathLevel1DialectParser.ParseUpdate(PutFragmentType[] putFragments)
at Microsoft.ResourceManagement.WebServices.ResourceManagementService.Put(Message request)

Here is the snipper of the C# code I'm using as the code-behind for the aspx page:
protected void Submit_Click(object sender, EventArgs e)
        {
            EnsureChildControls();
            try
            {
                this.txtErrorText.Text = String.Empty;
                this.trErrorRow.Style["display"] = "none";

                // Validate required fields.
                ValidateItems();

                // Generate requests.
                using (DefaultClient client = new DefaultClient())
                {
                    //client.RefreshSchema();

                    this.Success.Clear();
                    this.Failed.Clear();
                    RmAttributeName explicitGroupAttributeName = new RmAttributeName(_groupAttributeName);
                    RmAttributeName justificationAttributeName = new RmAttributeName(_updateAttributeName);
                    RmReference user = GetCurrentUserReference(client, this.UserDomainName, this.UserAccountName);


                    foreach (ListItem group in ctrlGroups.Items)
                    {
                        foreach (RmResource rmResource in client.Enumerate("/Group[ObjectID='" + group.Value + "']"))
                        {
                        
                            using (RmResourceChanges transaction = new RmResourceChanges(rmResource))
                            {
                                transaction.BeginChanges();
                                try
                                {
                                    if (rmResource.Attributes.ContainsKey(explicitGroupAttributeName))
                                    {
                                        if (rmResource.Attributes[explicitGroupAttributeName].Values.Contains(user))
                                        {
                                            throw new Exception("You are already a member of this group.");
                                        }
                                        rmResource.Attributes[explicitGroupAttributeName].Values.Add(user);
                                    }

                                    if (rmResource.Attributes.ContainsKey(justificationAttributeName))
                                    {
                                        rmResource.Attributes[justificationAttributeName].Value = this.BusinessJustification;
                                    }
                                    else
                                    {
                                        rmResource.Attributes.Add(justificationAttributeName, new RmAttributeValueSingle(this.BusinessJustification));
                                    }

                                    try
                                    {
                                        client.Put(transaction); // THROWS EXCEPTION!!!!!!!!!!!
                                        this.Success.Add(new KeyValuePair<string, string>(rmResource.DisplayName, "Added membership."));
                                    }
                                    catch (System.ServiceModel.FaultException ex)
                                    {
                                        if (ex.Message.Equals("Permission is required", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            this.Success.Add(new KeyValuePair<string, string>(rmResource.DisplayName, "Pending approval."));
                                        }
                                        else
                                        {
                                            throw new Exception("Authorization failed." + ex.Message);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    this.Failed.Add(new KeyValuePair<string, string>(rmResource.DisplayName, ex.Message));
                                }
                            }
                            break;
                        }
                    }
                }

                // Close window if all requested submits processed successfully.
                if (this.Failed.Count == 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), new Guid().ToString(), "<script type=text/javascript> window.opener=self; window.close();</script>");
                }
                else
                {
                    // Display any errors or status messages.
                    this.btnSubmit.Enabled = false;
                    this.txtReason.Enabled = false;
                    if (this.Success.Count > 0)
                    {
                        foreach (KeyValuePair<string, string> item in this.Success)
                        {
                            TableRow newRow = new TableRow();
                            TableCell newGroup = new TableCell();
                            TableCell newStatus = new TableCell();
                            newGroup.Text = item.Key;
                            newGroup.Style.Add("border", "solid 1px black");
                            newStatus.Text = item.Value;
                            newStatus.Style.Add("border", "solid 1px black");
                            newRow.Cells.Add(newGroup);
                            newRow.Cells.Add(newStatus);
                            this.tblSuccess.Rows.Add(newRow);
                        }
                    }
                    else
                    {
                        TableRow newRow = new TableRow();
                        TableCell newMessage = new TableCell();
                        newMessage.ColumnSpan = 2;
                        newMessage.Text = "No group memberships have been submitted.";
                        newMessage.Style.Add("border", "solid 1px black");
                        newRow.Cells.Add(newMessage);
                        this.tblSuccess.Rows.Add(newRow);
                    }

                    foreach (KeyValuePair<string, string> item in this.Failed)
                    {
                        TableRow newRow = new TableRow();
                        TableCell newGroup = new TableCell();
                        TableCell newStatus = new TableCell();
                        newGroup.Text = item.Key;
                        newGroup.Style.Add("border", "solid 1px black");
                        newStatus.Text = item.Value;
                        newStatus.Style.Add("color", "Red");
                        newStatus.Style.Add("border", "solid 1px black");
                        newRow.Cells.Add(newGroup);
                        newRow.Cells.Add(newStatus);
                        this.tblFail.Rows.Add(newRow);
                    }
                    this.StatusTable.Visible = true;
                }
            }
            catch (Exception ex)
            {
                // Display Error message.
                this.txtErrorText.Text = ex.Message;
                this.trErrorRow.Style["display"] = "table-row";
            }
        }
Seems like the exception is thrown everytime at client.Put(transaction). I have verified that the code is able to succesfully get the user object ID as well as the group ID, so I'm lost when does committing the change throw an exception.

Any help will be much appreciated :)
Coordinator
Jul 31, 2013 at 7:21 AM
Maybe this could be related to your custom attribute. Have you tried without it?
Also, it would be nice if you could provide a simple code snippet that illustrates the problem (rather then your whole method).
Cheers,
Paolo
Jul 31, 2013 at 9:19 AM
Hi Paolo,

Yes indeed the problem was my custom attribute, I forgot to extend the FIM schema with it.. D'oh!!