Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rally SOAP API-如何向分层需求添加附件?_Rally - Fatal编程技术网

Rally SOAP API-如何向分层需求添加附件?

Rally SOAP API-如何向分层需求添加附件?,rally,Rally,我已经按照添加附件到层次结构要求 我得到以下错误: validation error: Attachment.attachments[0] should not be null 如何将附件添加到分层需求中?您能否发布一段代码摘录来说明此问题?如果你在工作中遵循这种方法,你就走上了正确的道路。以下是我在向故事添加附件时使用的快速代码示例: // issue query for target story QueryResult queryResult = servi

我已经按照添加附件到
层次结构要求

我得到以下错误:

validation error: Attachment.attachments[0] should not be null

如何将附件添加到分层需求中?

您能否发布一段代码摘录来说明此问题?如果你在工作中遵循这种方法,你就走上了正确的道路。以下是我在向故事添加附件时使用的快速代码示例:

        // issue query for target story
        QueryResult queryResult = service.query(workspace, objectType, queryString, orderString, fetchFullObjects, start, pageSize);

        // look at the object returned from query()
        Console.WriteLine("Query returned " + queryResult.TotalResultCount + " objects");

        // Grab the resulting story
        DomainObject rallyObject = queryResult.Results.First();
        HierarchicalRequirement queryStory = (HierarchicalRequirement)rallyObject;

        // Read In Image Content
        String imageFilePath = "C:\\Users\\username\\";
        String imageFileName = "image1.png";
        String fullImageFile = imageFilePath + imageFileName;
        var imageFileLength = new FileInfo(fullImageFile).Length;
        Image myImage = Image.FromFile(fullImageFile);

        Console.WriteLine("Image File Length: " + imageFileLength);

        // Convert Image to Byte Array format
        byte[] imageByteArray = ImageToByteArray(myImage, System.Drawing.Imaging.ImageFormat.Png);
        var imageNumberBytes = imageByteArray.Length;

        // Create the Attachment Content
        AttachmentContent attachmentContent = new AttachmentContent();
        attachmentContent.Content = imageByteArray;
        attachmentContent.Workspace = workspace;
        CreateResult result = service.create(attachmentContent);
        attachmentContent = (AttachmentContent)result.Object;

        // Create the Attachment Container, wire it up to the AttachmentContent
        Attachment myAttachment = new Attachment();
        myAttachment.ContentType = "image/png";
        myAttachment.Content = attachmentContent;
        myAttachment.Name = "image1.png";
        myAttachment.Size = imageNumberBytes ;
        myAttachment.SizeSpecified = true;
        myAttachment.User = user;
        myAttachment.Artifact = queryStory;
        myAttachment.Workspace = workspace;

        // Create the attachment in Rally
        result = service.create(myAttachment);
        Console.WriteLine(result.Object);

    }

    public static byte[] ImageToByteArray (Image image, System.Drawing.Imaging.ImageFormat format)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            // Convert Image to byte[]
            image.Save(ms, format);
            byte[] imageBytes = ms.ToArray();

            return imageBytes;
        }
    }
}

非常感谢。它起作用了。我所做的不同之处在于创建附件内容,然后创建附件并分配给HierarchicalRequirement对象,然后创建HierarchicalRequirement。我现在已经将其更改为创建HierarchycalRequirement,然后创建附件,它工作得非常完美。再次感谢。如果您同意以上回答您的问题,请将答案标记为已接受-这有助于识别标签论坛中已回答的问题。