function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PathikritPathikrit 

Create Attachment from SOAP header

Hi,

I have a requirement to write an apex web service which accepts attachments and creates the same in SFDC. My question is, is it possible to create a webservice which allows the source system to send the attachment data through SOAP header? 

To elaborate my point, please refer to the Apex class below:
global class createAttachment{
webservice static String createAttachment(String parent, List<MultipleAttachments> multiAtt )
    {
        try
        {
            Id parentRecordId=Id.ValueOf(parent);
            List<Attachment> listAtt = new List<Attachment>();
           
            for(MultipleAttachments at : multiAtt)
            {
                Attachment att = new Attachment();
                att.Name=at.title;
                att.Body=EncodingUtil.base64Decode(at.content);//at.content;
                att.ContentType=at.ContentType;
                att.parentId=parentRecordId;
                listAtt.add(att);
            }
           
            insert listAtt; 
        }
        catch(Exception e)
        {
            system.debug('Exception--> '+e.getMessage());
        }
        return 'Yes!!!';
    }
   
    global class MultipleAttachments
    {
        webservice String title {get;set;}
        webservice String contentType {get;set;}
        webservice String content {get;set;}
    }
}

The generated WSDL from this apex class allows to send the attachment data through SOAP body. This works fine when used from SOAP UI. But if I want to send the same through SOAP header, is it possible to implement? Any pointers would be helpful.

Thanks!
Best Answer chosen by Pathikrit
PathikritPathikrit
Hi Prasannta,

Thanks for the pointer. After some research I figured that the source application (technology: .NET) cannot send the huge attachments via SOAP body due to time out issue. Hence one needs to bind the attachment in the header and send it. The middleware can do the mapping of sending the attachment data to SFDC in SOAP body and the above code works just fine. 

Thanks..

All Answers

PrasanntaPrasannta (Salesforce Developers) 
Hi,

Please refer to the link below to know about Creating Attachment from SOAP header-

http://www.xyzws.com/scdjws/studyguide/saaj_print.html


http://www.w3.org/TR/2000/NOTE-SOAP-attachments-20001211

Hope this helps.
PathikritPathikrit
Hi Prasannta,

Thanks for the pointer. After some research I figured that the source application (technology: .NET) cannot send the huge attachments via SOAP body due to time out issue. Hence one needs to bind the attachment in the header and send it. The middleware can do the mapping of sending the attachment data to SFDC in SOAP body and the above code works just fine. 

Thanks..
This was selected as the best answer