0

We need to send a file of xbrl format (a type of xml) to a receiving system. However, the receiving system requires that we are sending some form data as well. Regarding the xbrl file we need to send with it a form data, name="data".

Regarding the second part, we need to send an email to the system via form data. And that is name="email".

(I'll be the first to admit that I really do not understand form data at all so I cant explain much better than this).

I have a custom pipeline and in the encode stage I have put my pipeline component (the entire Execute method is down below) and after that a MIME/SMIME component (standard Microsoft).

Take a look at how the request looks like when it is being sent from Postman (and fully accepted by the receiving system):

Content-Type: multipart/form-data; boundary=--------------------------035085236562027409735938
Content-Length: 299420

----------------------------035085236562027409735938
Content-Disposition: form-data; name="data"; filename="Dk_{5AA9547A-E103-40CD-A2F4-6B77F010E570}.xbrl"
Content-Type: application/xml

<?xml version="1.0" encoding="utf-8"?>
  
<!- ---- Lots of removed xbrl ---- ->

</xbrli:xbrl>
----------------------------035085236562027409735938
Content-Disposition: form-data; name="email"
Content-Type: text/plain

test@test.com
----------------------------035085236562027409735938--

Now what you see below is what we have managed to achieve this far:

MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="_E9E8D52C-4722-488D-9FEC-713446D4A5C4_"

--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_
MIME-Version: 1.0
Content-Type: application/xml; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Content-ID: {E8CA3F1A-F953-4FFB-A054-DEB8466A5D86}
Content-Description: body

<?xml version="1.0" encoding="utf-8"?>

<!- ---- Lots of removed xbrl ---- ->

</xbrli:xbrl>
--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-ID: {3B35ECAC-990D-458C-8E7E-9C178CA99988}
Content-Description: email
Content-Disposition: attachment; filename="=?utf-8?B?QXR0YWPobWVudDF=?="

test@test.com
--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_--

Now, a quick comparison reveals that we are closing in on the solution. The first important issue must be that the Content-Type (first part below MIME-version: 1.0) is becoming multipart/mixed when we need multipart/form-data.

Second issue is in the Content-Disposition which for both parts does not, at all, look like expected.

Please take a look at my pipeline component. What you see is the entire code from the Execute. Since formDataPart.Data only takes a stream I have a method that translates a string to a stream (MemoryStream).

// Variables
var outMsg = pContext.GetMessageFactory().CreateMessage();
outMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);  
outMsg.Context.Promote("ContentType", "http://schemas.microsoft.com/BizTalk/2003/http-properties", "multipart/form-data;");

// Process xbrl file
var msgPart = pContext.GetMessageFactory().CreateMessagePart();

msgPart.PartProperties.Write("FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "SomeID.xbrl");
msgPart.PartProperties.Write("ContentDescription", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "xml");
//msgPart.PartProperties.Write("ContentTransferEncoding", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "7bit");
           
msgPart.Data = pInMsg.BodyPart.Data;
msgPart.ContentType = "application/xml"; 
msgPart.Charset = "UTF-8";
outMsg.AddPart("data", msgPart, true); 

// Form data (email)
var formDataPart = pContext.GetMessageFactory().CreateMessagePart();
formDataPart.ContentType = "text/plain";
formDataPart.Charset = "utf-8";
formDataPart.PartProperties.Write("ContentType", "http://schemas.microsoft.com/BizTalk/2003/http-properties", "form-data;");

formDataPart.Data = GenerateStreamFromString("test@test.com");
            
outMsg.AddPart("email", formDataPart, false); 

            
return outMsg;

Does anybody know whow we can achieve this? I can also mention that we are using the MIME/SMIME component after this custom pipeline component.

I really think that the solution from Greg Forsythe would be the best solution since I would have total control over the message but I have no idea how to translate that into actual code. Greg_suggestion

UPDATE: After so many trials and not coming anywhere we decided to ditch the above solution and go with Gregs solution instead. There is an issue there so I hope some C# guru can help us out. Please take a look at the new question if you are struggling with the form data request issue. Second attempt here

Emperor 2052
  • 517
  • 1
  • 5
  • 14
  • What is your custom pipeline component doing? Is it possible that you can get it to do the MIME encoding as well, and you will have more control over the parts. – Dijkgraaf Feb 03 '22 at 19:33
  • Hi @Dijkgraaf, I hope my revised post will be a bit clearer. If not, I will try to answer your questions again. – Emperor 2052 Feb 04 '22 at 07:54
  • What happens if you don't have the MIME encoder component after your custom one? Because it looks like you may be already creating what you need, with the MIME component. The other option in that thread is to use the MIME component before a custom component, that then changes the Content-Type that what is desired. – Dijkgraaf Feb 04 '22 at 10:05
  • I tried both of your suggestions. First one only sends the original xbrl file (not accepted message by the receving system). The second, with the mime component before my own returns a error that states that some class has not been registered. Trying to fix that issue now. (The issues with this task never ends....) – Emperor 2052 Feb 07 '22 at 09:06
  • After so many issues with the above mentioned code we decided to go with Greg Forsythes solution. We have a slight issue there so I will open a new question. I think this one should be easier since the request is made by code instead. I really hope some C# guru can see where we miss out. – Emperor 2052 Feb 09 '22 at 15:46

0 Answers0