BizTalk - 设置电子邮件内容类型导致错误:XML 文档中有错误 (1, 1)

问题描述

当我尝试在 BizTalk 编排中设置 Microsoft.XLANGs.BaseTypes.ContentType 时,我收到一个 XML 错误(无论我使用的是“text/plain”还是“text/xml”。我使用的是动态使用 Passthru 管道发送端口。

msg_Email.BodyPart = new Ledger6002.Component.RawString("See attached email. Method 2"); 
msg_Email.AttachmentPart = msg_Ledger6002_File_XmlDoc;

// Set the filename as it should display on the attachment in the email 
// (drop the path,just the filename/extension)
attachmentName = System.IO.Path.GetFileName(
                       msg_Ledger6002_File_XmlDoc(FILE.ReceivedFileName));

msg_Email.AttachmentPart(MIME.FileName) =  attachmentName; 

msg_Email.BodyPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
msg_Email.AttachmentPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";

导致此错误

xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'Ledger6002.Logic.Ledger6002_Process_File(9eb6993c-87d0-7bf0-b0bf-e1f684000af2)'.
The service instance will remain suspended until administratively resumed or terminated. 
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 216e4bac-0f22-4e06-9e61-2ef46051c991
Shape name: msg_Email
ShapeId: e7ce3f54-0558-4756-a7e4-e3800721178f
Exception thrown from: segment 1,progress 55
Inner exception: There is an error in XML document (1,1).
        
Exception type: InvalidOperationException
Source: System.Xml
Target Site: System.Object Deserialize(System.Xml.XmlReader,System.String,System.Xml.Serialization.XmlDeserializationEvents)
The following is a stack trace that identifies the location where the exception occured

   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
   at Microsoft.XLANGs.Core.Value.Getobject(Type t)
   at Microsoft.XLANGs.Core.Value._prepareForWrite(PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.ValueTable.PrepareForWrite(Valuetoken& vt,PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.Part.PrepareForWrite(PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.Part.SetPartProperty(Type propType,Object val)
   at Microsoft.XLANGs.Core.Part.SetPropertyValue(Type propType,Object val)
   at Ledger6002.Logic.Ledger6002_Process_File.segment1(StopConditions stopOn)
   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s,StopConditions stopCond,Exception& exp)
Additional error information:

        Data at the root level is invalid. Line 1,position 1.
        
Exception type: XmlException
Source: System.Xml
Target Site: Void Throw(System.Exception)
The following is a stack trace that identifies the location where the exception occured

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res,String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Xml.XmlReader.MovetoContent()
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderObject.Read2_anyType()
    

msg_email 是一个多部分消息,包含两部分:bodyPart 和attachmentPart,两者都定义为一个 RawString 自定义类。

可能导致此错误的原因是什么?我是否需要使用 MIME/编码器的管道?

我现在在另一个客户处,尝试回答 2017 年的问题(但使用编排而不是管道):How Set Attachment Name to Show Properly in Outlook

当我注释掉设置 contentType 的两行时,我收到一封电子邮件,但与上面 2017 年帖子中提到的问题相同。

解决方法

您至少缺少两件事:

  • 使用 SMTP.MessagePartsAttachments 设置并将其设置为“2”
  • 使用 SMTP.EmailBodyTextCharset 并将其设置为“UTF-8”

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...