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

WSDL Question


This might be a really stupid question but how do I use the WSDL generated by (From the generate screen in setup)?

I have many custom fields which I need access to but so far I have had no luck in adding the WSDL to my VB.NET project.

It would be great if someone could give me a little idiots guide?


Many Thanks, JT

Click the "Download Enterprise WSDL" link and save the generated file to disk, e.g. c:\enterprise.wsdl

In your VB project, right click on the references section in solution explorer and select add web reference. In the dialog that pops up, enter c:\enterprise.wsdl as the URL to the WSDL and click go. In the Web Reference name text entry (middle right of the dialog) change the default WebReference to something more useful like sforce and hit ok.


I guess I'm at the same starting point. I've managed to bring in the wsdl to the Web References as described and named it 'sforce'.

Next I brought in the walk-through code found elsewhere on the site.

But I must have missed a step somewhere because I get a compile error saying

"The type or namespace name 'sforce' could not be found (are you missing a using directive or an assembly reference?)"

The 1st line where sforce is mentioned is "private sforce.SforceService binding; "

Any ideas?




If you are using VB .Net you will need to "fix" the reference.vb file (might be webreference.vb) which is hidden under the web reference node.  The case and event attributes of the sobject need to be [bracketed].

Sorry, no vb files that I can see anywhere. Just Visual C# .NET

Maybe I should reinstall Visual Studio, yes?

Seems unlikely that that's the problem. Right click on the sforce web reference in solution explorer and select view in object model, what does that show as the class name ?

well, in the Class View under salesForce there is

salesForce CodeNameSpace
     sforce CodeNameSpace
           all the CodeClasses
     Global CodeClass




I see sObject CodeClass under sforce CodeNameSpace where right-clicking gives me links to definition, reference, etc.

by the way, thanks for your patience



I have updated the web reference to the WSDL on my local drive and enclosed Case and Event in brackets.

But I am still getting the error "type sObject is not defined".

Does anyone have any ideas where the problem is?

Thanks in advance.


"and enclosed Case and Event in brackets."

Not sure how or where this can be done. In the wsdl file? Could you send me a snippet?




Hi hfeist and JT,

You fellas seem to be adrift.  JT - you are using VB .Net? hfeist - you are using C#?

Can you, have you tried the VB .Net and C# samples on this site?  Do you need to namespace qualify your sObject or use imports or using?

Would mind pasting some code snippets?



adrift, yes. took quite a while to paddle back here

I'm using C# in VS so wonder if the bracketing solution is for me. i seem to remember reading that C# didn't share in that problem. Here's my walkthrough code that gets the error "The type or namespace name 'sforce' could not be found (are you missing a using directive or an assembly reference?)":

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace walkThrough {

class WalkthroughSample {

private sforce.SforceService binding;

static private WalkthroughSample walkthroughSample;


static void Main(string[] args) {

walkthroughSample = new WalkthroughSample();;


public void run() {

//Call the login function

if ( login() ) {

//Do a describe global


//describe an account object


//retrieve some data using query




private bool login() {

//Get the user name and password from the console

Console.Write("Username: ");

string username = Console.ReadLine();

Console.Write("Password: ");

string password = Console.ReadLine();

//create a new instance of the web service proxy class

binding = new sforce.SforceService();

try {

//execute the login placing the results

//in a LoginResult object

sforce.LoginResult loginResult = binding.login(username, password);

//set the session id header for subsequent calls

binding.SessionHeaderValue = new sforce.SessionHeader();

binding.SessionHeaderValue.sessionId = loginResult.sessionId;

//reset the endpoint url to that returned from login

binding.Url = loginResult.serverUrl;

return true;


catch (Exception ex) {

//Login failed, report message then return false

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

return false;



private void describeGlobal() {

//The describe global will return an array of object names that

//are available to the logged in user

sforce.DescribeGlobalResult dgr = binding.describeGlobal();

Console.WriteLine("\nDescribe Global Results:\n");

//Loop through the array echoing the object names to the console

for (int i=0;i<dgr.types.Length;i++) {



Console.WriteLine("\n\nHit enter to continue...");



private void describeSObject(string objectType) {

//Call the describeSObject passing in the object type name

sforce.DescribeSObjectResult dsr =


//The first properites we will echo are on the object itself

//First we will output some Descriptive info on the object

Console.WriteLine("\n\nObject Name: " +;

if (dsr.custom) Console.WriteLine("Custom Object");

if (dsr.label != null) Console.WriteLine("Label: " + dsr.label);

//now the permissions on the object

if (dsr.activateable) Console.WriteLine("Activateable");

if (dsr.createable) Console.WriteLine("Createable");

if (dsr.deletable) Console.WriteLine("Deleteable");

if (dsr.queryable) Console.WriteLine("Queryable");

if (dsr.replicateable) Console.WriteLine("Replicateable");

if (dsr.retrieveable) Console.WriteLine("Retrieveable");

if (dsr.searchable) Console.WriteLine("Searchable");

if (dsr.undeletable) Console.WriteLine("Undeleteable");

if (dsr.updateable) Console.WriteLine("Updateable");

//Now we will retrieve meta-data about each of the fields

for (int i=0;i<dsr.fields.Length;i++) {

//Create field object for readability

sforce.Field field = dsr.fields[i];

//Echo some useful information

Console.WriteLine("Field name: " +;

Console.WriteLine("\tField Label: " + field.label);

//This next property indicates that this

//field is searched when using

//the name search group in SOSL

if (field.nameField)

Console.WriteLine("\tThis is a name field.");

if (field.restrictedPicklist)

Console.WriteLine("This is a RESTRICTED picklist field.");

Console.WriteLine("\tType is: " + field.type.ToString());

if (field.length > 0)

Console.WriteLine("\tLength: " + field.length);

if (field.scale > 0)

Console.WriteLine("\tScale: " + field.scale);

if (field.precision > 0)

Console.WriteLine("\tPrecision: " + field.precision);

if (field.digits > 0)

Console.WriteLine("\tDigits: " + field.digits);

if (field.custom)

Console.WriteLine("\tThis is a custom field.");

//Output the permission on this field.

if (field.nillable) Console.WriteLine("\tCan be nulled.");

if (field.createable) Console.WriteLine("\tCreateable");

if (field.filterable) Console.WriteLine("\tFilterable");

if (field.updateable) Console.WriteLine("\tUpdateable");

//If this is a picklist field, we will show the values

if (field.type.Equals(sforce.fieldType.picklist)) {

Console.WriteLine("\tPicklist Values");

for (int j=0;j<field.picklistValues.Length;j++)

Console.WriteLine("\t\t" + field.picklistValues[j].value);


//If this is a foreign key field (reference),

//we will show the values

if (field.type.Equals(sforce.fieldType.reference)) {

Console.WriteLine("\tCan reference these objects:");

for (int j=0;j<field.referenceTo.Length;j++)

Console.WriteLine("\t\t" + field.referenceTo[j]);




Console.WriteLine("\n\nHit enter to continue...");



private void querySample() {

//The results will be placed in qr

sforce.QueryResult qr = null;

//We are going to limit our return batch size to 3 items

binding.QueryOptionsValue = new sforce.QueryOptions();

binding.QueryOptionsValue.batchSize = 3;

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) {


for (int i=0;i<qr.records.Length;i++) {

sforce.Contact con = (sforce.Contact)qr.records[i];

string fName = con.FirstName;

string lName = con.LastName;

if (fName == null)

Console.WriteLine("Contact " + (i + 1) + ": " + lName);


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" + ex.Message);


Console.WriteLine("\n\nHit enter to exit...");








my immediate goal is to login via browser, lookup a contact's cases by email address then loop through them to make a list
Nick @ AKCSLNick @ AKCSL

Hi Hfeist

In the Solution Explorer under Web References, is the sforce web reference named "sforce" or "sForce"?

You code uses "sforce".

If you find you code and the Web Reference name don't match, you can either change your code, or change the "Folder Name" property of the Web Reference.

I think some of the downloadable examples use "sForce" and some use "sforce".

Just a thought.




Thanks for the help Nick.

No it's 'sforce' everywhere that I can see.

The code is made up of snippets from the sample 'Walkthrough" C# code at

I'm thinking there must be some step I should have taken in setting up the sample within VS.

I am having the same problem since upgrading to Visual Studio 2003.  My C# project was working fine until I made the upgrade and grabbed the latest WSDL for my organization.  I'm wondering if SalesForce changed something in their latest release that is creating an incompatibility with VStudio?  I cannot figure this out!

I too am running Visual Studio 2003 with C#.

I'm also a complete newbie to dotnet dragged kicking and screaming from gold old asp. This does not help, I know. Too many learning curves stacked one upon the other...


Hi fellas,

Let's start with a brand new VS project (command window or windows form).  Add the web reference by typing into the dialog window*.   You will need to provide your credentials to the login page that is displayed.  Once you've done that and the wsdl file is read and parsed by the dialog, change the name of the web reference to sforce and click Add Reference.

Then, on the form or in the main class, try to use the web reference using the fully qualified name of the the class (<projectname>.sforce.SforceService).  If you can get this far, then you should be on your way.  You can cut and past the sample bits you want.


After following your step-by-step I at least get a different error: "A using namespace directive can only be applied to namespaces; 'sforcetest.sforce.SforceService' is a class not a namespace)" sforcetest is the project name. If I remove it and use "using sforce.SforceService" I get the error, "The type or namespace name 'sforce' could not be found (are you missing a using directive or an assembly reference?)" as before


using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using sforcetest.sforce.SforceService;


namespace routines


/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page


private void Page_Load(object sender, System.EventArgs e)


// Put user code to initialize the page here




Can you post the top 20 lines or so of reference.cs (click one of the buttons at the top of solution explorer to get it to show all files, reference.cs will then be under your sforce web reference\ tree)

Hi hfeist,

Your using clause for sforce goes to far.  Try

using sforcetest.sforce;

sforcetest.sforce is the "package" reference, where as SforceService is a class reference.  The using statement is for library or "package" definitions.


Well that got it to build ok--progress!

As a next step I opened the walkThrough sample and replaced every 'sforce.' with 'sforcetest.sforce' and it compiled ok.

When I Start it the browser shows an error:


Parser Error Message: Could not load type 'walkThrough.walkThrough'.

Source Error:

Line 1:  <%@ Page language="c#" Codebehind="walkThrough.aspx.cs" AutoEventWireup="false" Inherits="walkThrough.walkThrough" %>

Source File: c:\inetpub\wwwroot\sforcetest\walkThrough.aspx    Line: 1

Perhaps I should start with something simpler


hi zak,

here are the top 20 lines from Reference.cs you asked for:


// <autogenerated>

// This code was generated by a tool.

// Runtime Version: 1.1.4322.573


// Changes to this file may cause incorrect behavior and will be lost if

// the code is regenerated.

// </autogenerated>



// This source code was auto-generated by Microsoft.VSDesigner, Version 1.1.4322.573.


namespace sforcetest.sforce {

using System.Diagnostics;

using System.Xml.Serialization;

using System;

using System.Web.Services.Protocols;

using System.ComponentModel;

using System.Web.Services;


Forget about my last post re walkthrough not working.

Since I want to get things working on the web instead of the console I found the sample file called aspsample.zp in another thread and tried to get it going.

After a search/replace session changing 'sforce' to 'sforcetest.sforce' evrything compiles and runs ok!

Thanks for all the help guys. At least I'm moving a little bit...