Q:

How to tell specifics about SOAP exception

I'm wondering if there is a way to use specific error information using the Salesforce API and C#. Basically my login attempt is surrounded by a try...catch statement which catches any System.Web.Services.Protocols.SoapException.
This is great but I want to handle an incorrect password differently from any other error, and currently catch (SoapException wsError) gets any SOAP Exception and currently the only way I can tell the difference is using the error message text at runtime.
Is there a more specific exception type I should be using? Or am I missing something?

A:

Its generally good practice for API's not to differentiate between the specific cause of login failure to much, e.g. invalid user vs invalid password, so response codes are generally pretty vague. However Salesforce does provide a fault code for its API's. The response for an invalid login looks like this...
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>INVALID_LOGIN</faultcode>
         <faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring>
         <detail>
            <sf:LoginFault xsi:type="sf:LoginFault">
               <sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode>
               <sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage>
            </sf:LoginFault>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

In the case of System.Web.Services.Protocols.SoapException class you can access the faultcode element via the code property. And the LoginFault XML structure via the detail property. The Salesforce Fault responses are described here.

