+ Start a Discussion
Carl_V1Carl_V1 

Errors getting the partner WSDL working in Visual C# 2008

Hi All,
 
Question - trying to get the C# samples working in Visual C# 2008 Express Edition and having seemingly successfully imported a Partner WSDL into the project as a web reference (named 'sforce' per the API docs) I get the following runtime error repeatedly when trying to compile and run -
 
The type or namespace name 'SforceService' could not be found (are you missing a using directive or an assembly reference?) 
 
In addition, I also get the following warnings -
 
Custom tool warning: Schema validation error: Schema item 'simpleType' named 'FaultCode' from namespace 'urn:fault.partner.soap.sforce.com' is invalid. The Enumeration constraining facet is invalid - 'fns' is an undeclared namespace. 
 
and
 
Custom tool warning: Schema could not be validated. Class generation may fail or may produce incorrect results. 
Being a newbie to C# development I'd love to get the samples going but cant get beyond these initial issues - any suggestions would be most appreciated.  All I've done is copy the login sample to a button click method.
 
Cheers,
Carl_V
 
SuperfellSuperfell
The schema warnings are actually long standing bugs in the .NET schema tools, the schema is actually correct.

The C# samples on the site for are .NET 2.0, VS.NET 2008 however defaults to using WCF based web service clients, and not the previous system.web.services based stubs. When you import the WSDL, you can click the advanced button and there's an option at the bottom of that dialog box called compatibility that'll let you create a .NET 2.0 style web services client.
Carl_V1Carl_V1
Thanks Simon for the help.

I tried as you suggested and having been overrun with errors,warnings and a stubborn refusal from the IDE to compile my 'helloworld' style project I guess I'll just move on to Java...shame.

Cheers,
Carl_V
DDeanDDean
Fortunately I haven't had this error in VS2005 or VS2008... but out of curiosity (and in case I do encounter it) I did another import on the WSDL and looked for this advanced button.  I couldn't find it.  Where should I see this button so I can make the changes you mentioned, in the event I'd need to?

Maybe someone else will find this useful too? :)
Carl_V1Carl_V1
Dude - if you've been able to achieve an error-free partner WSDL import and able to compile in VS2008, maybe you could point me in the right direction?  I'll do screenshot of advanced button in VS2008 for you, but would be great to confirm I've imported wsdl correctly...

Any input most appreciated!

Cheers,
Carl_V
DDeanDDean

Since I haven't had the problem, it'd probably be hard to tell you what you're doing wrong, if anything.  Besides... doesn't sound like it's a user error issue at all... Simon knows his stuff pretty well.  :)

Anyway, I log in to salesforce, go get the WSDL, save it to my project's folder, open VS, right click on the project and do "Import Web Reference", type in the patch (including the actual file name), hit go, chose a name, add reference, and all is well.

I just realized you guys were using the "Import Service Reference" thing instead, and that's where the advanced button is, which just launches the same Web Reference wizard I use directly.

Maybe my way is not the recommended way, but it has always worked. <shrug>



DDeanDDean
Sorry, it's "Add Web Reference", not "Import Web Reference".


I should also probably mention that, by default, I have these other reference in the project...

System.Core - GAC - Ver 2.5
system.Data.DataSetExtensions - GAC - 3.5
system.web.extensions - GAC - 3.5
System.xml.linq - GAC - 3.5

The target framework for build is .NET Framework 3.5.




Message Edited by DDean on 04-14-2008 04:05 PM
DDeanDDean

I just reread your original post.

The error you're getting is because you're apparently referencing a namespace that isn't in scope.  Everywhere your examples have the sforceservice, try replacing them with "sforce.sforceservice".  If that works, you have a scope issue.  Post back here if that's the case... you'll probably solve it with an "Imports sforce" statement before your class declaration.

As for the warnings... I pay less attention to them, and they probably aren't stopping your build.  Warnings are often relatively benign heads-up messages.


SuperfellSuperfell
Here's a quick sample.
a) start VS.NET 2008 c# express edition
b) create a new windows console application
c) pick add service reference, click advanced, click add web reference (at the bottom)
d) enter c:\partner.wsdl as the filename and click go, enter sforce as the reference name (having previously downloaded the wsdl from the salesforce.com app to c:\partner.wsdl)
e) enter this code

using System;

namespace queryTest
{
class Program
{
static void Main(string[] args)
{
sforce.SforceService s = new sforce.SforceService();
sforce.LoginResult lr = s.login(args[0], args[1]);
s.SessionHeaderValue = new sforce.SessionHeader();
s.SessionHeaderValue.sessionId = lr.sessionId;
s.Url = lr.serverUrl;

sforce.QueryResult qr = s.query("select name from account");
foreach(sforce.sObject a in qr.records)
Console.WriteLine("{0}", a.Any[0].InnerText);
}
}
}


run it as queryTest.exe [username] [password]

compiled and ran fine for me using VS.NET 2008 C# express edition on WinXP.

Message Edited by SimonF on 04-14-2008 04:56 PM
Carl_V1Carl_V1
You boys are firing! Most appreciated :smileyvery-happy:

Using the procedure above and a console project template, I got 6 errors and  warnings... same as before. Bizarre.
**Addendum ** - provided demo works fine now thankyou. Not sure how I fixed it, but it works

I notice the example you've kindly provided is for a console app - the app I have tried to build thus far was a windows forms app - just dropped a button onto the provided form and then added the sample code into the 'on click' method i.e

private void button1_Click(object sender, EventArgs e)
        { stick sforce demo in here
          }

I have a bad feeling that this is not the right way to do things... do you guys know of a 'Hello World' project file for VS2008 that shows where the bindings, services etc get dropped in? Whilst Im keen to try C# I am finding that all demos are for console style apps - to use a form based UI would be great, but understanding where things go is proving elusive.

I certainly dont expect that this sort of request can be serviced - thought I'd ask anyway :) - and thanks again for your input to this point.

Cheers,
Carl_V



Message Edited by Carl_V1 on 04-14-2008 06:14 PM

Message Edited by Carl_V1 on 04-14-2008 06:42 PM
Carl_V1Carl_V1
Ok - thanks Dean and Simon,

Have managed to get a form app working using C# and VS2008. Am underway. Appreciate the leg up and hope can return the favour one day :smileyhappy:

Cheers,
Carl_V
Big EarsBig Ears

Unfortunately, the QueryTest code produces, in my instance, an error message as follows:

"'Walkthrough.sforce.sObject' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'Walkthrough.sforce.sObject' could be found (are you missing a using directive or an assembly reference?)"

The namespace and sforce reference file match up (hence it saying Walkthrough, rather than QueryTest).

I'm also having the problems stated by the original poster. However, mine is the enterprise WSDL.

Any additional help would be appreciated, if available.

Thank you!



Message Edited by Big Ears on 07-28-2008 09:21 AM
SuperfellSuperfell
the code i posted is for the partner WSDL, it will not work with the enterprise WSDL.
Big EarsBig Ears
That would explain it!
 
Also, the code on the Salesforce Tutorial Website seemed to posisbly have some errors that were causing the hi-jinx I was experiencing.
 
Thank you,
Andy