如何通过SOAP请求将PDF作为base64编码的字符串发送?

时间:2018-06-07 11:32:01

标签: c# xml

我正在尝试通过SOAP请求将其转换为基本的64位编码字符串来发送PDF文件,但是从此请求收到的测试邮件不包含任何附件。请记住,在这些事情上我是新手,所以请对我温柔:)

    //If the current person has been assigned an API-key, send the mail and delete the PDF from its directory afterwards.
        if (!String.IsNullOrEmpty(person.apiKey))
        {
            //Instantiate a new Mail object with the information required to send it via the SOAP request
            //and a MailAttachment to store in the attachments-array.
            Mail _mail = new Mail() { toPersId = person.ID, subject = "", msg = "", attachments = new MailAttachment[] { new MailAttachment() } };

            //Instantiate a byte array containing the PDF in the specified directory.
            byte[] pdfArray = File.ReadAllBytes(person.fullFilePath);

            //Convert the byte array to a base 64-string and attach it to the fileContent of Mail.attachments.
            _mail.attachments[0].fileName = person.fullFilePath;
            _mail.attachments[0].fileContent = Convert.ToBase64String(pdfArray);

            //Instantiate a new Mail array to use as input parameter in the SOAP request,
            //containing the mail object specified above.
            Mail[] mail = new Mail[] { _mail };

            //Send SOAP request and receive SOAP response.
            var request = new SoapRequest(person.apiKey, mail);
            var task = client.SoapRequestAsync(request);
            var response = task.Result as SoapResponse;

            //If something is returned in the response, the request has succeeded.
            //Add information to the result string to be able to display it in the log.
            if (response.return.Length > 0)
            {
                resultString += "mail has been sent successfully. ";
                resultString += FileHandler.DeleteFileFromDirectory(person.fullFilePath);
            }
        }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.SoapTypeAttribute(Namespace = "https://apiftp.quinyx.com/soap/FlexForce")]
public partial class MailAttachment
{

    private string fileNameField;

    private string fileContentField;

    /// <remarks/>
    public string fileName
    {
        get
        {
            return this.fileNameField;
        }
        set
        {
            this.fileNameField = value;
        }
    }

    /// <remarks/>
    public string fileContent
    {
        get
        {
            return this.fileContentField;
        }
        set
        {
            this.fileContentField = value;
        }
    }
}

我收到回复和确认电子邮件,但正如我所说,它不包含任何附件。我一直在读MTOM等,但我不确定它是如何工作的。我的问题是Web服务XML解析器不理解附件是base64编码的吗?如果不清楚,此方法将Person人员作为输入参数。

我会非常感谢任何可以指向正确方向的输入。

提前致谢。

0 个答案:

没有答案