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
opiedogopiedog 

Receiving intermittent protocol error and "(500) internal server error"

I have an implementation for a client that works most of the time.

 

When it doesn't work, I'm receiving a WebException.Status of ProtocolError with an HttpWebResponse.StatusCode of InternalServerError.

 

Could you provide some guidance about what might cause this? I log the SOQL query strings and they can be run successfully so I assume it's in the way I'm constructing the HTTP headers.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

API sessions expire on inactivity, if there's a long enough gap between your api requests the session will get expired, and you'll need to call login again.

All Answers

forcedotcomforcedotcom

Without further info I think it'll be hard to determine the cause as internal server error is too general... have you tried putting debug lines in your apex class?

opiedogopiedog

Hi,

 

I should have been more informative with my first post. I'm calling Salesforce from a .NET app - the implementation is not Apex.

 

The challenge I'm having is with the general reply from the server. My hope is that the WebException of ProtocolError would be enough for somebody to say "in that case, look for X, Y, or Z which can cause that to happen." I'm really at a loss given that the SOQL queries that I'm sending to Salesforce are valid (I test them in independent code to confirm I'm not passing a bad Id or missing fields or something like that).

 

Thanks for any help or ideas you might have!

SuperfellSuperfell

SOAP Faults are returned with a http status code of 500, as required by the soap spec. You should have a soap fault body (which typically .NET will translate into an exception for you) to go with that 500 error.

opiedogopiedog

Sorry if I'm misunderstanding what you're saying, but what I got from the WebException that .NET threw was the ProtocolError and the "(500) internal server error".

 

For example, here's the code where the exception occurred (I removed extraneous code to hopefully make it as clear as possible):

 

public override WebResponse GetResponse()      

{

  WebResponse response = null;

  try

  {

  response = m_wr.GetResponse(); // FYI, m_wr == "private WebRequest m_wr;" 

  }

catch( WebException wex )

  {

StringBuilder sb1 = new StringBuilder();

  sb1.AppendFormat( "Exception: GetResponse: WebException Status={0}", wex.Status );

  ServerControl.SFLog( sb1.ToString() );

 

HttpWebResponse httpWR = (HttpWebResponse) wex.Response;

StringBuilder sb2 = new StringBuilder();
sb2.AppendFormat( "StatusCode={0}; StatusDescription={1}", httpWR.StatusCode, httpWR.StatusDescription );
ServerControl.SFLog( sb2.ToString() );

 

}

}

SuperfellSuperfell

Are you not using the .NET soap stack? What I'm saying is that the response with a 500 status code includes an HTTP body, that is a soap fault that will have much more specific details of what went wrong. You (or your framework) need to look at the response HTTP body to find out the real error message.

opiedogopiedog

Ah - gotcha. This is what was returned:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_SESSION_ID</faultcode><faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: 00DA0000000ITsb!AQMAQCsBr.HKkBCun6IziqNOZH1xkikToRHp7LnM9rXYCFy.mtkXiqixg5WpqcybuDzs1M.ZRsGGhFqDxJ7WhggJMXORNamb</faultstring><detail><sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault"><sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode><sf:exceptionMessage>Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: 00DA0000000ITsb!AQMAQCsBr.HKkBCun6IziqNOZH1xkikToRHp7LnM9rXYCFy.mtkXiqixg5WpqcybuDzs1M.ZRsGGhFqDxJ7WhggJMXORNamb</sf:exceptionMessage></sf:UnexpectedErrorFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>

 

I'm getting the sessionId from the LoginResult returned from the login call, and this works for a while but then stops working. I doubt the solution is to logout/login if/when this happens...

 

Thanks for your help!

SuperfellSuperfell

API sessions expire on inactivity, if there's a long enough gap between your api requests the session will get expired, and you'll need to call login again.

This was selected as the best answer
opiedogopiedog

Thanks for your help with this!