使用SOAP将PDF文件作为附件添加到TestTrack

时间:2013-01-23 21:24:08

标签: c# pdf soap attachment testtrack

我最近在过去的一年里开始使用C#,所以我对此有点新鲜,但通常可以通过一些努力来破解,但是这一个让我望而却步。我们在我们公司使用TestTrack进行开发错误/问题跟踪。我已经为我们的一个部门创建了一个自定义Windows窗体应用程序作为TestTrack的前端。它使用SOAP连接。我没有使用WPF / WCF,也不想走那条路。我很难找到如何正确编码PDF附件的文件的示例。下面的代码实际上在TestTrack中创建了一个已存在问题的附件,但是当您尝试在TestTrack中打开它时,会弹出一条错误消息,显示“图像数据不足”。如果您想使用SOAP向TestTrack添加文本文件,下面的示例可以正常工作。我想知道我需要在下面更改什么,以便我可以将PDF文件放入TestTrack,然后能够在TestTrack应用程序中打开它而不会出现上述错误。提前感谢任何输入/帮助。

    public void getAttachments(long lSession, CDefect def)
    {
        ttsoapcgi cgiengine = new ttsoapcgi();

        // Lock the defect for edit.
        CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);

        string attachment = "c:\\TEST\\TEST_PDF.PDF";

        CFileAttachment file = new CFileAttachment();
        file.mstrFileName = Path.GetFileName(attachment);

        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

        StreamReader reader = new StreamReader(attachment);
        file.mstrFileName = Path.GetFileName(attachment);
        file.mpFileData = enc.GetBytes(reader.ReadToEnd());
        reader.Close();

        CReportedByRecord reprec = lockedDefect.reportedbylist[0];
        CFileAttachment[] afile = reprec.attachmentlist;
            if (afile == null)
            {
                lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
                lockedDefect.reportedbylist[0].attachmentlist[0] = file;
            }

            // Save our changes.
            cgiengine.saveDefect(lSession, lockedDefect);
    }
}

1 个答案:

答案 0 :(得分:0)

以下是修改后的方法,它允许我将PDF附加到SOAP并将其作为问题的附件加入TestTrack:

        public void getAttachments(long lSession, CDefect def)
    {
        ttsoapcgi cgiengine = new ttsoapcgi();

        // Lock the defect for edit.
        CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);

        string attachment = "c:\\TEST\\TEST_PDF.PDF";

        CFileAttachment file = new CFileAttachment();

        file.mpFileData = File.ReadAllBytes(attachment);
        file.mstrFileName = Path.GetFileName(attachment);

        CReportedByRecord reprec = lockedDefect.reportedbylist[0];
        CFileAttachment[] afile = reprec.attachmentlist;
            if (afile == null)
            {
                lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
                lockedDefect.reportedbylist[0].attachmentlist[0] = file;
            }

            // Save our changes.
            cgiengine.saveDefect(lSession, lockedDefect);
    }