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
DigitalManDigitalMan 

C# Sample Code does not work.

Ok, trying to integrate with the WSDL from a C# web app in VS2005. After fixing some simple mistakes in the example code such as "qr.recrods" etc, I'm still having issues. In the login method there is this line:

sfdc.GetUserInfoResult userInfo = lr.userInfo;

However, GetUserInfoResult is not a member of that object.
The closest I see in intellisense is getUserInfo but that does not work. Is there anotehr example that works? I apologize but I'm completely new to SalesForce and just trying to estimate a project to integrate some simple web forms on a client site to automatically push the data to their salesforce database. I've worked with WebServices before just not this API.

SuperfellSuperfell
There's been a userInfo property on LoginResult for about 2 years, are you sure you're using a current WSDL ?
DigitalManDigitalMan
The LoginResult object is not the issue. The code in the walkthru is:

sfdc.GetUserInfoResult userInfo = lr.userInfo; 

sfdc is a SforceService object.

GetUserInfoResult is not a member of the SforceService.

All I see in intellisense is sfdc.getUserInfo

SuperfellSuperfell
sfdc is also a namespace, GetUserInfoResult is a class in that namespace.
DigitalManDigitalMan
Error    4    The type or namespace name 'sfdc' could not be found (are you missing a using directive or an assembly reference?) 

                // Create a new session header object
                // Add the session ID returned from the login
                sfdc.SessionHeaderValue = new SalesForce.SessionHeader();
                sfdc.SessionHeaderValue.sessionId = lr.sessionId;
                sfdc.GetUserInfoResult userInfo = lr.userInfo;

The error is only on the last line. If I comment it out like:

                // Create a new session header object
                // Add the session ID returned from the login
                sfdc.SessionHeaderValue = new SalesForce.SessionHeader();
                sfdc.SessionHeaderValue.sessionId = lr.sessionId;
                //sfdc.GetUserInfoResult userInfo = lr.userInfo;

It compiles fine.

And if I type sfdc. in VS2005, "GetUserInfoResult" is not a choice.



SuperfellSuperfell
Where'd you get the sample code from ?, what namespace did you put the WSDL in when you did add web reference ?
DigitalManDigitalMan
I downloaded the enterprise wsdl from my client's account. I then added it to VS 2005.

Sample code is here:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_samplecode.htm#topic-title_csharp


SuperfellSuperfell
You're probably better off downloading the full sample code/project, rather than trying to recreate it peicemeal from the snippits in the docs. see http://wiki.apexdevnet.com/index.php/API#.NET
DigitalManDigitalMan
Ah, cool. Thank you.
zero1578zero1578
I had this same problem with the documentation.  The samples appear to be a single long example, but when you view one of the specific functions in the documentation, it takes you to a sample of that same piece of code that is written differently.  The part I missed was:

private SforceService binding = new SforceService();

And then use binding through the project instead of the SforceService 'sfdc' that you create inside the login call, but I was working with a webapp, not a console app like the samples.

 

 

Code:

private SforceService binding = new SforceService();

protected void Page_Load(object sender, EventArgs e)

{

if (login())

{

doWhatever();

}

}

private bool login()

{

LoginResult lr = binding.login("name", "pass"); if (!lr.passwordExpired) { binding.Url = lr.serverUrl; binding.SessionHeaderValue = new SessionHeader(); binding.SessionHeaderValue.sessionId = lr.sessionId; GetUserInfoResult userInfo = lr.userInfo; return true; } else { Response.Write("Your password is expired."); return false; }

}
 

DigitalManDigitalMan
Thanks much zero1578. My test is now working.
ZitizonXZitizonX

I think its syntax error. I found this in the API Doc too. You should change the code little bit then it will work. :smileywink:

 

Code:

    public SforceService sfdc = new SforceService();
    private LoginResult loginResult = null;

    
    protected void Page_Load(object sender, EventArgs e)
    {
        sfdc = new SforceService();
        try
        {
            LoginResult lr = sfdc.login(username, passwd);
            sfdc.Url = lr.serverUrl;

            sfdc.SessionHeaderValue = new SessionHeader();
            sfdc.SessionHeaderValue.sessionId = lr.sessionId;
           

            //Displaying the Session ID and URL
            Label1.Text = "The session id is: " + lr.sessionId;
            Label1.Text += "<br />The new server url is: " + lr.serverUrl;
           
            //Displaying the user Details
            GetUserInfoResult userResults = new GetUserInfoResult();
            userResults = sfdc.getUserInfo();
            Label1.Text += "<br />User Name : " + userResults.userFullName;
            Label1.Text += "<br />User Email : " + userResults.userEmail;
            Label1.Text += "<br />User License : " + userResults.licenseType;
        }

        catch (Exception exp)
        {
            Label1.Text = exp.ToString();
        }
    }


 
Zitizon X