I am currently working on a project to interface out .Net Core 3.1 application to Salesforce. Unfortunately I am not very familiar with Salesforce and their SOAP API. I have been attempting to find various solutions to log into SF and access the custom objects. I have downloaded the Enterprise WSDL and made the appropriate changes as discussed in previous posts. I added the web service to my C# Core 3.1 Console app and attempting to login. Unfortunately, I have not been successful and I have sent a tremendous amount of time trying to figure this out; so any help is much appreciated.

Here is the code I am currently working on (NOTE: I am connecting to the test environment of Salesforce):

using FSS_SFService;        // Salesforce Web Service
using System;
using System.ServiceModel;
using System.Threading.Tasks;
namespace ConsoleApp2
    class Program

        static string userName = "<<USERNAME>>";
        static string password = "<<PASSWORD>>";
        static string securityToken = "<<TOKEN>>";
        static SoapClient sc;
        static loginResponse lresp;
        static LoginResult lres;
        static LoginScopeHeader lsr = null;
        static string serverUrl;
        static string sessionId;

        static void Main(string[] args)
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            var loginAddress = new EndpointAddress("https://test.salesforce.com/services/Soap/c/54.0/0DF7A00000004fr");

            sc = new SoapClient(binding, loginAddress);

        static async void Run()
            lresp = await SfLogin();
            lres = lresp.result;
            serverUrl = lres.serverUrl;
            sessionId = lres.sessionId;

        static async Task<loginResponse> SfLogin() 
            loginResponse lr = await sc.loginAsync(null, userName, password + securityToken);
            return lr;

When LoginAsync() is executed, the application hangs and then just shuts down. I notice the SoapClient doesn't appear to be setup correctly when viewing the properties of the object.

I appreciate the help. Bob

  • There's an example in salesforce.stackexchange.com/questions/189927/…
    – identigral
    Commented Apr 7, 2022 at 5:22
  • Thank you for pointing out the example, which my code is based upon. However it appeared to be missing some information which required additional research on my part. I ended up adding the synchronous methods from the WSDL because I could not get the async function to work properly.
    – Bob P
    Commented Apr 7, 2022 at 13:30

1 Answer 1


After additional research and changes to the code, I was finally able to connect (I think) to the organization. Next up...performing a Query. Here is my updated code for completeness:

        static void Main(string[] args)
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            var loginAddress = new EndpointAddress(new Uri("https://test.salesforce.com/services/Soap/c/54.0/"));

            // Establish login
            sc = new SoapClient(binding, loginAddress);
            lres = sc.login(null, userName, password + securityToken);

            // Constitute a query
            SessionHeader header = new SessionHeader();
            header.sessionId = lres.sessionId;

            QueryOptions qopts = new QueryOptions();
            qopts.batchSize = 250;
            qopts.batchSizeSpecified = true;

            string query = "SELECT FirstName,Id,LastName FROM Contact";

            QueryResult qr = null;
            LimitInfo[] li = sc.queryAll(header, qopts, query, out qr);   // Not working


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .