You need to sign in to do that
Don't have an account?
Trying to get .NET Sample working
In the querySample() code, how does VS know what the Contact data type is? I get this error message:
Error 1 The type or namespace name 'Contact' could not be found (are you missing a using directive or an assembly reference?)
I added WSDL to the web references and named it sForce.And I am using the following libraries.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;
using Program.sforce;
namespace Program
{
class Program
{
static public SforceService binding;
static void Main(string[] args)
{
Console.Write("Enter username: ");
string username = Console.ReadLine();
Console.Write("Enter password: ");
string password = Console.ReadLine();
// Create a service object
binding = new SforceService();
// Timeout after a minute
binding.Timeout = 60000;
// Try logging in
LoginResult lr;
try
{
Console.WriteLine("LOGGING IN NOW...");
lr = binding.login(username, password);
}
// ApiFault is a proxy stub generated from the WSDL contract when
// the web service was imported
catch (SoapException e)
{
// Write the fault code to the console
Console.WriteLine(e.Code);
// Write the fault message to the console
Console.WriteLine("An unexpected error has occurred: " + e.Message);
// Write the stack trace to the console
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
private void querySample()
{
//The results will be placed in qr
QueryResult qr = null;
//We are going to increase our return batch size to 250 items
//Setting is a recommendation only, different batch sizes may
//be returned depending on data, to keep performance optimized.
binding.QueryOptionsValue = new QueryOptions();
binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
try
{
qr = binding.query("select FirstName, LastName from Contact");
bool done = false;
if (qr.size > 0)
{
Console.WriteLine("Logged-in user can see "
+ qr.records.Length + " contact records.");
while (!done)
{
Console.WriteLine("");
for (int i = 0; i < qr.records.Length; i++)
{
Contact con = (Contact)qr.records[i];
string fName = con.FirstName;
string lName = con.LastName;
if (fName == null)
Console.WriteLine("Contact " + (i + 1) + ": " + lName);
else
Console.WriteLine("Contact " + (i + 1) + ": " + fName
+ " " + lName);
}
if (qr.done)
{
done = true;
}
else
{
qr = binding.queryMore(qr.queryLocator);
}
}
}
else
{
Console.WriteLine("No records found.");
}
}
catch (Exception ex)
{
Console.WriteLine("\nFailed to execute query succesfully," +
"error message was: \n{0}", ex.Message);
}
Console.WriteLine("\n\nHit enter to exit...");
Console.ReadLine();
}
}
}
All Answers
Here is a screenshot that may help.
VS Configuration