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
ManishDhuparManishDhupar 

URGENT: Error while making a Login call using C#

We are trying to integrate one of our Commerce Application with our Salesforce Instance and during the login call we receive the following error using C#/.NET.  However the login works through  console application however throws the above error through the .dll (compiled with the same code) which is called by our Commerce Application.

 

Exception : System.Web.Services.Protocols.SoapHeaderException: Required field/property SforceService.LoginScopeHeaderValue of SOAP header LoginScopeHeader was not set by the client prior to making the call.
at System.Web.Services.Protocols.SoapHeaderHandling.GetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client)
at System.Web.Services.Protocols.SoapHttpClientProtocol.BeforeSerialize(WebRequest request, String methodName, Object[] parameters)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Mercury_SFAdapter.Sforce.SforceService.login(String username, String password)
at Mercury_SFAdapter.Mercury_SFAdapterSvc.login()

 

Further,  when we provide the organisationId, (as below) – (Commented in The Source Code Shared Below)

binding.LoginScopeHeaderValue = new Mercury_SFAdapter.Sforce.LoginScopeHeader();
binding.LoginScopeHeaderValue.organizationId = "Our Org ID";

the Exception changes to the one below:

 

Exception : System.Web.Services.Protocols.SoapException: INVALID_LOGIN: Invalid username or password, locked out or Self-Service portal is not enabled
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Mercury_SFAdapter.Sforce.SforceService.login(String username, String password)
at Mercury_SFAdapter.Mercury_SFAdapterSvc.login()

 

The same username/Password works absolutely fine through the Web Interface and Console Application. We also tried to use the Security Token along with the Password but with no Luck.

 

The Source Code used is as Below:

 

 

private bool login()

{

binding = new Mercury_SFAdapter.Sforce.SforceService();

try

{

//execute the login placing the results

//in a LoginResult object

//binding.LoginScopeHeaderValue = new Mercury_SFAdapter.Sforce.LoginScopeHeader();

//binding.LoginScopeHeaderValue.organizationId = "00D500000007nEo";

Mercury_SFAdapter.Sforce.LoginResult loginResult = binding.login("username", "password");

if (!loginResult.passwordExpired)

{

binding.Url = loginResult.serverUrl;

//set the session id header for subsequent calls

binding.SessionHeaderValue = new Mercury_SFAdapter.Sforce.SessionHeader();

binding.SessionHeaderValue.sessionId = loginResult.sessionId;

return true;

}

else

{

QLogWrapper.m_staticLogger.logComment("Password is Expired");

}

}

catch (Exception ex)

{

QLogWrapper.m_staticLogger.logComment("Exception : " + ex);

}

//Login failed, report message then return false

//--------Console.WriteLine("Login failed with message: " + ex.Message);

return false;

}


 

 

Request some immediate assistance on this.

 

Thank you,

Manish K Dhupar

SuperfellSuperfell
What version of .NET are you using? I've never seen that before. You could create the LoginScopeHeader instance, but set no properties on it, that should work ok.
ManishDhuparManishDhupar
Thanks Simon. It worked !!!!
chercher

When the client is trying to consume a salesforce web service using c#, the following error is comming up: Invalid sessionID? what might be the reason?

SuperfellSuperfell

You didn't set the sessionId, or you set the sessionId, but sent the request to the wrong server, or the session Id you've got has expired (either by time, or because of an explicit logout)

chercher

Actually it is the error that the client is getting when he is invoking the my salesforce webservice method using c# in visual studio.  do i need to make the changes that you sugested in my wsdl? or is it the problem from the client side

 thnsk for replying

SuperfellSuperfell

Did they call login and set the sessionId header? going need some details, can you post the code.