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
satyaprakash palsatyaprakash pal 

SOAP Web Service error

I created apex SOAP web service which accepts attachments and creates the same in SFDC.
for testing I am using "SoapUI" tool for testing.
I am getting below error Please help me out, I am new in web service:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Client</faultcode>
         <faultstring>content-type of the request should be text/xml</faultstring>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>
=====================================================

Please find below request which I am passing:


// Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.sforce.com/schemas/class/SOAPWebservice">
   <soapenv:Header>
      <soap:AllowFieldTruncationHeader>
         <soap:allowFieldTruncation>false</soap:allowFieldTruncation>
      </soap:AllowFieldTruncationHeader>
      <soap:DebuggingHeader>
         <!--Zero or more repetitions:-->
         <soap:categories>
            <soap:category>Callout</soap:category>
            <soap:level>None</soap:level>
         </soap:categories>
         <soap:debugLevel>None</soap:debugLevel>
      </soap:DebuggingHeader>
      <soap:CallOptions>
         <soap:client></soap:client>
      </soap:CallOptions>
      <soap:SessionHeader>
         <soap:sessionId>00D540000008ju2!AQ4AQNh0Een86V3.P4mMmvbdUTHZQWk0f.XobQ1</soap:sessionId>
      </soap:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <soap:candidateInformation>
         <soap:name>testUser</soap:name>
         <soap:att>
            <!--Optional:-->
            <soap:content></soap:content>
            <!--Optional:-->
            <soap:contentType>text/xml</soap:contentType>
            <!--Optional:-->
            <soap:title>test</soap:title>
         </soap:att>
      </soap:candidateInformation>
   </soapenv:Body>
</soapenv:Envelope>

// SOAP Class
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;}
    }
}
pconpcon
I believe your error is that you are not sending the correct data to your web service.  I would suggest that you re-download the WSDL for your createAttachment class and then regenerate your data.  Your payload should look something like
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.sforce.com/schemas/class/createAttachment">
    <soapenv:Header>
        <soap:SessionHeader>
             <soap:sessionId>xxxx</soap:sessionId>
        </soap:SessionHeader>
    </soapenv:Header>
    <soapenv:Body>
        <soap:createAttachment>
         <soap:parent>YYYY</soap:parent>
         <soap:multiAtt>
            <soap:content>ZZZZ</soap:content>
            <soap:contentType>text/xml</soap:contentType>
            <soap:title>test</soap:title>
         </soap:multiAtt>
      </soap:createAttachment>
   </soapenv:Body>
</soapenv:Envelope>

NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.