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
akash gupta034856688323083473akash gupta034856688323083473 

Getting error 500 Internal server error

Getting error 500 Internal server error (Soap Action Http header missing)  while fetching data using BulkApi.
Ashish_SFDCAshish_SFDC
Hi Akash, 


Need some more information on this, 

Enable debug logs and see where exactly the code is breaking, 

Already there is an Action defined in the soap request URI : req.setHeader('SOAPAction', '');

See the below link for related discussion, 

http://salesforce.stackexchange.com/questions/18762/having-problem-calling-soap-webservice


Regards,
Ashish


akash gupta034856688323083473akash gupta034856688323083473
Hi Ashish 
thnx for your quick reply ,
i have enabled error logs and here is the error:-

The assembly with display name 'BulkApi.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'BulkApi.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'BulkApi.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

=== Pre-bind state information ===
LOG: User =xxx
LOG: DisplayName = BulkApi.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=x86
(Fully-specified)
LOG: Appbase = file:///C:/Users//documents/visual studio 2010/Projects/BulkApi/BulkApi/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\xxx\documents\visual studio 2010\Projects\BulkApi\BulkApi\bin\Debug\BulkApi.vshost.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/xxx/documents/visual studio 2010/Projects/BulkApi/BulkApi/bin/Debug/BulkApi.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/Users/xxx/documents/visual studio 2010/Projects/BulkApi/BulkApi/bin/Debug/BulkApi.XmlSerializers/BulkApi.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/Users/xxx/documents/visual studio 2010/Projects/BulkApi/BulkApi/bin/Debug/BulkApi.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///C:/Users/xxx/documents/visual studio 2010/Projects/BulkApi/BulkApi/bin/Debug/BulkApi.XmlSerializers/BulkApi.XmlSerializers.EXE.
Ashish_SFDCAshish_SFDC

Hi Akash, 


Can you also post the code and the line where it is breaking. 


Regards,

Ashish

akash gupta034856688323083473akash gupta034856688323083473
here is the code and highlighted is the line where it is breaking.

(sent in two parts because of the lenth)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Threading;
using BulkApi.com.salesforce.na15;
using System.Diagnostics;
using System.Xml;
using System.Xml.XmlConfiguration;
using System.Web.Services.Protocols;
using BulkApi.Properties;
using System.Web;
using System.Security.Policy;


namespace BulkApi
{
    class Program
    {
        private  void QueryUsingBulkAPI()
       {
           string jobId = string.Empty;
            string resultId = string.Empty;
            string batchId = string.Empty;
            Console.Write("Enter user name: ");
            string userName = Console.ReadLine();
            Console.Write("Enter password: ");
            string password = Console.ReadLine();
  Console.WriteLine("Creating the binding to the web service...")
 SforceService service = new SforceService();
             service.Timeout = 60000;

             Console.WriteLine("LOGGING IN NOW....")
 try
            {
                LoginResult loginRes = service.login(userName, password);
                Console.WriteLine(loginRes);
                Console.WriteLine("The session id is: " + loginRes.sessionId);
                Console.WriteLine("The new server url is: " + loginRes.serverUrl);
              
             
                service.Url = loginRes.serverUrl;

             
                service.SessionHeaderValue = new SessionHeader();
                service.SessionHeaderValue.sessionId = loginRes.sessionId;
                Debug.WriteLine(loginRes.sessionId);

                CreateJob(loginRes.sessionId,"query","case",jobId);
              
              
                byte[] inputFileData = null;

                if ((jobId.Length > 0))
                {
                  
                    System.IO.FileInfo oFile = null;
              
                    oFile = new System.IO.FileInfo("request.txt");

                    System.IO.FileStream oFileStream = oFile.OpenRead();
                    long lBytes = oFileStream.Length;
                    int a = (int)lBytes;
                    if ((lBytes > 0))
                    {
                        byte[] fileData = new byte[lBytes];
                       
                        oFileStream.Read(fileData, 0, a); 
                        oFileStream.Close();

                       
                        inputFileData = fileData;
                    }

                 
                    AddBatch(loginRes.sessionId, inputFileData, jobId, batchId, resultId);

                   GetStatusAndRetrieveBatchIdAndResultsId(loginRes.sessionId, jobId,  batchId,  resultId);
                   
                   RetrieveResults(loginRes.sessionId, jobId, batchId, resultId);
                }
            }
            catch (System.Web.Services.Protocols.SoapException e)
            {
               
                Console.Write(e.Message + ", please try again." + "Hit return to continue...");
                Console.ReadLine();

            }
            catch (Exception ex)
            {
               
                Console.Write(ex.Message + ", please try again." + "Hit return to continue...");
                Console.ReadLine();

            }
}
               public void CreateJob(string sfSessionId, string sfOperation, string sfObjectName, string jobId)
               {
                  string str = string.Empty;
                  string reqURL  = string.Empty;
                  byte[] bytes = null;
      
                  XmlDocument reqDoc = default(XmlDocument);
                  XmlDocument responseXmlDocument = new XmlDocument();
             
                   str = ""+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<jobInfo xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">"
                           + "<operation></operation>" + "    <object></object>" + "<contentType>XML</contentType>" + "</jobInfo>";

                   reqURL = "https://na15-api.salesforce.com/services/async/29.0/job/";
                   reqDoc = new XmlDocument();
                   reqDoc.LoadXml(str);
     
          
                    // added XML modifications


                    reqDoc.GetElementsByTagName("operation")[0].InnerText = sfOperation;
                    reqDoc.GetElementsByTagName ("object")[0].InnerText =  sfObjectName;
                    bytes = System.Text.Encoding.ASCII.GetBytes(reqDoc.InnerXml);
                    using (Stream responseStream = Post(bytes, reqURL, sfSessionId, "POST", "text/csv;charset=UTF-8"))
                    {
                        responseXmlDocument.Load(responseStream);
                        //Get jobId
                        jobId = ((((responseXmlDocument) != null)) ? responseXmlDocument.GetElementsByTagName("id").Item(0).InnerText : "");
                    }
                } 
                   public void AddBatch(String sfSessionId,
                            Byte[] fileBytes,
                            String sfJobId,
                            string sfBatchId,
                            string resultid)//check how to define optional parameter in C# i think it doesnt allow?
                      {

                          String requestURI = ("https://login.salesforce.com/services/async/29.0/job/" +
                           (sfJobId + "/batch"));
                          Post(fileBytes, requestURI, sfSessionId, "POST", "text/csv;charset=UTF-8");

                       }


                    public void GetStatusAndRetrieveBatchIdAndResultsId(string sfSessionId, string sfJobId,  string batchId,  string resultId)
     
                          {
                             XmlDocument responseXmlDocument = new XmlDocument();
                             String reqURL = ("https://na15-api.salesforce.com/services/async/29.0/job/" +
                             sfJobId + "/batch");
                             using (Stream responseStream = Post(null, reqURL, sfSessionId, "GET", "text/csv;charset=UTF-8"))
                                {
                                   responseXmlDocument.Load(responseStream);
                                   batchId = ((((responseStream) != null)) ? responseXmlDocument.GetElementsByTagName("id").Item(0).InnerText : "");
                                 }

                             
                             reqURL = ("https://na15-api.salesforce.com/services/async/29.0/job/" +
                                (sfJobId + "/batch/" + batchId + "/result"));

                             using (Stream responseStream = Post(null, reqURL, sfSessionId, "GET", "text/csv;charset=UTF-8"))
                                {
                                   responseXmlDocument.Load(responseStream);
                                   resultId = ((((responseStream) != null)) ? responseXmlDocument.GetElementsByTagName("result").Item(0).InnerText : "");
                                }
     
                          }

                    
            
akash gupta034856688323083473akash gupta034856688323083473
Remaining part

public void RetrieveResults(String sfSessionId,
                               String sfJobId,
                               String sfBatchId,
                               String sfResultId)
                          {

                              String reqURL = ("https://na15-api.salesforce.com/services/async/29.0/job/" +
                                                   (sfJobId + "/batch/" + sfBatchId + "/result/" + sfResultId));
                              String  localFile  = "output.xml";
                          
                              using (Stream responseStream = Post(null, reqURL, sfSessionId, "GET", "text/csv;charset=UTF-8"))
                                {
                              using (FileStream fsOutputFile = new FileStream (localFile, FileMode.Create, FileAccess.Write))
                                  {
                                   byte[] buffer = new byte[2048];
                                   int read = 0 ;
                                   do
                                    {
                                      read = responseStream.Read(buffer, 0, buffer.Length);
                                      fsOutputFile.Read(buffer, 0, read);
                                     }
                                    while (!(read == 0));
             
                                     responseStream.Close();
                                     fsOutputFile.Flush();
                                     fsOutputFile.Close();
                            
                                  }
                                responseStream.Close();
                                 }

                         }



                      public static Stream Post(byte[] bytes, string reqURL, string sfSessionId, string method, string contentType)
                      {
                           
                          HttpWebRequest requestHttp = (HttpWebRequest)WebRequest.Create(reqURL);
                            
                          requestHttp.Method = method;
                            
                          requestHttp.ContentType = "text/csv; charset=UTF-8";

                           requestHttp.Headers.Add("X-SFDC-Session:" + sfSessionId);
                        
                          if ((bytes != null))
                              {
                               requestHttp.ContentLength = bytes.Length;

                               Stream strmHttpContent = requestHttp.GetRequestStream();
                               strmHttpContent.Write(bytes, 0, bytes.Length);
                               strmHttpContent.Close();
                       
                        
                              }
                         
                               String responseFromServer;
                                try
                                 {
                                    HttpWebResponse response = (HttpWebResponse)requestHttp.GetResponse();
 
                                    if (HttpStatusCode.OK == response.StatusCode)
                                     {
                                      Stream dataStream = response.GetResponseStream();
                                      StreamReader reader = new StreamReader(dataStream);
                                      responseFromServer = reader.ReadToEnd();
                                      response.Close();
                                     }
                                 }
                               catch (WebException e)
                               {
                                using (WebResponse response = e.Response)
                               {
                                HttpWebResponse httpResponse = (HttpWebResponse)response;
                    
                                responseFromServer = string.Format("Error code: {0}  ", httpResponse.StatusCode);
                                using (Stream data = response.GetResponseStream())
                               {
                                responseFromServer += new StreamReader(data).ReadToEnd();
                            
                                   Console.WriteLine("reponse from server" + responseFromServer);
                                 }
                               }
                           }
                 
                       WebResponse responseHttpRequest = requestHttp.GetResponse();
                      return responseHttpRequest.GetResponseStream();
                      }


        static void Main(string[] args)
         {
            Program pr = new Program();
            pr.QueryUsingBulkAPI();
           }
     }
}
Ashish_SFDCAshish_SFDC
Hi Akash,


This is a MS Visualstudio error and is not significant. There are quite some blogs around which say this should be ignored.

This exception is a part of the XmlSerializer's normal operation. It is expected and will be caught and handled inside of the Framework code. Just ignore it and continue. If it bothers you during debugging, set the Visual Studio debugger to only stop on unhandled exceptions instead of all exceptions.

See the links below,

http://social.msdn.microsoft.com/Forums/en-US/9f0c169f-c45e-4898-b2c4-f72c816d4b55/strange-xmlserializer-error?forum=asmxandxml


http://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor

http://stackoverflow.com/questions/294659/why-did-i-get-an-error-with-my-xmlserializer


"I think you have enabled "Break on all exceptions" in Visual Studio -> Debug/Exceptions, you should ignore such exceptions at all."

http://support.x-tensive.com/question/2853/could-not-load-file-or-assembly-xtensivestoragemodelxmlserializers


Regards,
akash gupta034856688323083473akash gupta034856688323083473
Hi Ashish,

i did the same and now i am getiing the error 500  saying:-

The remote server returned an error: (500) Internal Server Error.

response from server
Error code : InternalServerError

<?xml version="1.0" encoding = "UTF-8"? >
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv : Body>
<soapenv:Fault>
<faultcode>
soapenv:Client
</faultcode>
<faultstring>
SOAPAction HTTP header missing>
Ashish_SFDCAshish_SFDC

Hi Akash, 


There is a Help and Training article for the issue, See in the below link, 

http://help.salesforce.com/apex/HTViewSolution?id=000133750&language=en_US


Regards,

Ashish
 

akash gupta034856688323083473akash gupta034856688323083473
Hi Ashish,

Thnx for ur reply

but this link is not useful for me as i am working with console application for fetching data.
I am trying to resolve this but still getting the same error.
Ashish_SFDCAshish_SFDC
Hi Akash, 


Can you get to the record out side of the Console and execute this in normal UI and see if this is only specific to Console or even on the UI. 

The code posted above does not have the highlight, can you repost that one line so that it will be easy to identify. 


Regards,
Ashish