views:

89

answers:

1

So I believe all you have to do with .NET 2.0 vanilla web services (not WCF) is the following:

1) Add your service reference. In my case I'm using the PayPal WSDL 2) Before you can use any proxy class, you must first create an instance of your service reference 3) Once you create an instance of your service reference, then just do [servicereference].ProxyClassName.Method or whatever you're trying to access from those classes

right?

Ok, so I tried that. I added a service reference and named it SandboxSoapAPI. So that's what you see under references in my C# project.

In code I tried this:

SandboxSoapApi reference = new SandboxSoapApi();

but it doesn't recognize SandboxSoapAPI. Am I doing something wrong? I just want to start calling class methods, etc. with PayPal and I can't seem to get this right.

And if I'm not incorrect, as of .NET 2.0+ it handles the low level sending of the actual request over Http for SOAP web service references?

+2  A: 

SandboxSoapAPI is not the SOAP client proxy type name. It's a namespace.

To check this, in VS.NET tick 'show all files' and drill into the Web References, open up the Reference.cs file, you will see the SandboxSoapApi is a subnamespace (not your SOAP client proxy name!) in the project's root namespace.

So either use the fully qualified name:

SandboxSoapAPI.YourProxyType client = new SanboxSoapAPI.YourProxyType();

Or use using SandboxSoapAPI; in your code where you need the SOAP client.

Wim Hollebrandse
thanks. So I do see [projectnamespace].WebServiceReferenceName in that Reference.cs and I do have a using [projectnamespace].WebServiceReferenceName in my C# class where I'm trying to create that instance. The message I get when hovering over SandboxSoapApi is "Type name expected but namespace name found"
CoffeeAddict
Yes, see my edit.
Wim Hollebrandse
Ah thanks. I did not know that there is an additional proxyType for the client. I thought that the reference itself was an object.
CoffeeAddict
You helped me a ton. I didn't infer all that even though yes I could have looked at the Reference.cs I still wouldn't infer to just go look for some client proxy class in the service. I wish there was better docs on .NET 2.0+ web services..without so much jargon. They use stuff like asynchronous calls..ok well I did not know that it's also inferred that under the covers it does all the low-level building of the request.
CoffeeAddict
Additionally, and likely of interest, is that under the hood, the 'Add Web Reference' functionality in VS.NET simply wraps the `wsdl.exe` command line utility which generates the proxy client and data types. You can equally add the generated .cs file manually to your project if you so wished. You may want to play around with `wsdl.exe` a bit. It will broaden your understanding of what goes on. Cheers!
Wim Hollebrandse
Yea thanks. I understand that the wsdl creates proxy classes. But in your example you're really talking about the soap client..not just any proxy class. Those are 2 different things.
CoffeeAddict
Well, I meant the SOAP proxy client yes, not the data contract proxy classes. But usually you don't end up calling those proxy class, even though they are, but refer to them as the data contracts, data types whatever.
Wim Hollebrandse