none
Attachment pickup using Unique value receieved and do a POST RRS feed

  • Question

  • I have a particular folder where there will be Attachments placed like .docx, .png, .pdf, .txt files.
    Each document will be pre-Appended by a unique value.

    There is a Web service that will be sending a XML file, which also has Unique value field.

    My requirement in BizTalk is depending on the Unique Value field received, BizTalk needs to grab that particular attachment and do a POST calling external API.
    How can I achieve this in BizTalk. Please advise

    RH


    • Edited by Dan2890 Monday, October 28, 2019 6:33 PM a
    Monday, October 28, 2019 6:31 PM

Answers

  • Which bit are you stuck on?  As most of that is just out of the box functionality.  The only bit that isn't is to pick up the attachment based on the prefix.

    There are two different approaches.

    1) You create a helper class that gets called to pick up the attachment based on the value in the XML.   You could call that from an Orchestration that has received the XML file from the web service.

    2) You could have a BRE rule in the receive pipeline for the file that promotes the unique value for the file, and you also promote (in the schema) the unique value in the XML payload, and an Orchestration that uses Correlation sets waits until it receives both the XML and the attachment file.

    Monday, October 28, 2019 8:21 PM

All replies

  • Which bit are you stuck on?  As most of that is just out of the box functionality.  The only bit that isn't is to pick up the attachment based on the prefix.

    There are two different approaches.

    1) You create a helper class that gets called to pick up the attachment based on the value in the XML.   You could call that from an Orchestration that has received the XML file from the web service.

    2) You could have a BRE rule in the receive pipeline for the file that promotes the unique value for the file, and you also promote (in the schema) the unique value in the XML payload, and an Orchestration that uses Correlation sets waits until it receives both the XML and the attachment file.

    Monday, October 28, 2019 8:21 PM
  • Well how will those Attachments convert to base 64 format (encoded) before I do a POST ?

    RH

    Monday, October 28, 2019 8:45 PM
  • well in the link provided he is writing that seperately in customer pipeline component.

    When I receive web service call, there is an element which has UniqueFileName need to store that, and after certain processing is success then only with the UniqueFileName grab the attachment  ( may be .docx, may be .pdf, may be .png, may be .txt)... convert that to base 64 encoded as pass this as a string value assigning to a destination field and do a POST call.

    Hope my scenario is clear, where I am stuck is after storing the value and after certain processing is success, how can I call the attachment and convert that to a string field and pass over when doing a POST call ?

    Please advise


    RH

    Monday, October 28, 2019 9:16 PM
  • Yes, so you either do the encoding the the pipeline of you are using an Orchestration to correlate, or you do the encoding in your helper class that picks up the attachment.
    Wednesday, October 30, 2019 12:47 AM
  • I like calling through helper class is better and easy.

    So I need to pass the UniqueId value as a parameter to the Helper class for that to recognize that particular document(attachment) and return that in encoded base64 value in the form of a string ? Is this the approach you are suggesting ?

    I tried below logic

    public byte[] GetFileContentByName(string id)
    {
        var file = Directory.GetFiles("c:\\temp", $"{id}.*").FirstOrDefault();
        if(file != null)
           return File.ReadAllBytes(file);
        return null;
    }

     

    RH

    Wednesday, October 30, 2019 1:06 AM
  • Yes, but you will want to convert it before returning it.

    return System.Convert.ToBase64String(File.ReadAllByes(file));

    Wednesday, October 30, 2019 1:11 AM
  • ok, I will update my code.

    Also my return type is byte[], when calling this assembly from orchestration I will assigning to a variable of type string right ?

    Also, when assigning this to schema what is the data Type field I have to choose ? Is it unsigned Byte or Base64binary ?




    • Edited by Dan2890 Wednesday, October 30, 2019 1:37 AM a
    Wednesday, October 30, 2019 1:15 AM
  • Definitely not usigned Byte, that is a 8 bit value.

    I would use a string, unless you identify a need for something else.

    Monday, November 4, 2019 12:37 AM
  • I was able to convert a pdf to string and assign to schema of type string and send it.

    Only 1 Attachment at a time

    But what if there are multiple attachments that needs to be delivered at same time when calling same API ? How can that be done ?

    Please advise

    Note : I am picking only the attachments which is having UniqueId as a parameter thats being sent.


    RH

    Monday, November 11, 2019 8:35 PM
  • It would depend on the capabilities of the API.  Is it capable of accepting that?  

    If yes, you would need to change your GetFileContentsByName so that it iterates through all the files and creates the necessary payload.

    Monday, November 11, 2019 8:48 PM
  • well I checked, the API can handle only 1 Attachment at a time.

    So do I need to modify my external helper class ? Do I need to add foreach loop in it ? Please advise


    RH

    Monday, November 11, 2019 9:07 PM
  • In that case, you would need to first get a list of all the files that match.

    Loop through those, and one at a time create and send the payload to the API.

    So yes, your external helper class will need to be changed.

    I would add a method to return a list of files that match the id.

    And change your current method to accept the full file name.

    Monday, November 11, 2019 9:11 PM
  • Will BizTalk be able to handle array of strings ? 

    I am receiving error as cannot convert from string[] to string

    public static string GetAttachmentBase64Strings(string path, string Id)
            {
    
                var file = Directory.GetFiles(path + "\\" + $"{Id}", $"*.*");
                if (file.Length != 0)
    
                    foreach (var filePath in file)
    
                    
                        return System.Convert.ToBase64String(File.ReadAllBytes(file));
    
                        return null;         
    }


    RH

    Monday, November 11, 2019 9:41 PM
  • No, BizTalk runtime won't handle a string array.

    You will have to make it into a XML payload, that you then iterate through the nodes.

    Monday, November 11, 2019 9:48 PM
  • I dont get it, do you have a link where I can reference please ?

    RH

    Monday, November 11, 2019 9:53 PM