Page 1 of 1

Web services - posting an XML file

Posted: Tue Jul 03, 2007 7:53 am
by Skittlewidth
I've been tasked with writing code to access 4 or 5 products on different companies' servers via web services (a collaborative nightmare, but that's another issue) and I'm a bit new to the whole Web Services concept. I've done some simple tutorials on writing web services that add two numbers together and then wrote code to remotely access them from a different project etc etc. I think I understand the basics.

Unfortunately no one else here has much experience on the topic and the colleague that does hasn't touched it for years. What he's suggesting I do is confusing me. His very general instructions went something like "dynamically generate your xml file, put a target url in the header and instruct it to post there, then wait for the response".

It doesn't sound like the exercises I've just done, which were more like putting a parameter into a function that just happened to belong to a remote web service. Surely I generate the file, and pass it as a parameter to each of the web services participating, and as the agreement goes, they can do what they will with the data within. I've not got as far as handling responses yet.

I'm using VB.NET/ASP.NET for this but if anyone could give me any pointers on what to google on, because I don't seem to be getting anywhere with "post XML file to web service". Even PHP examples will at least show me the principles.

Thanks!

Posted: Tue Jul 03, 2007 8:06 am
by volka
Is it a soap webservice and is there something called "wsdl"?

Posted: Tue Jul 03, 2007 8:28 am
by Skittlewidth
The information that has been chinese whispered to me is that we will use HTTP-POST requests. The actual web services I will be consuming have not yet been built since its taken a long time to agree on a common set of information to send to all 5 external products, so I'm just trying to learn how to generally do stuff in preparation for the real thing.

The examples I have looked at have included wsdl - at least Visual Studio seems to have helpfully generated a .wsdl file...

Posted: Tue Jul 03, 2007 10:22 am
by TheMoose
HttpWebRequest
HttpWebResponse

I personally haven't used SOAP much (IE: once), so I can't comment on that. Understanding how those 2 classes work and how to use them will ease your pain when trying to create a commonality between the different products.

Your best bet is for you to create a basic XML schema that will contain all the information you have coupled with all the information you want, and give that to the other companies and let them build their service around your XML spec. This way you can design your application to work off of a single XML spec and just have multiple requests to the different services using your own spec.

The actual posting of an XML file TO the web service is not difficult by any means. The 2 classes above will have lots of information regarding the different methods of sending requests (GET vs POST) and how to implement each.

If you need more info, let me know, and I can post some of the code I use. I deal with these methods daily inside VB.NET.

Posted: Tue Jul 03, 2007 3:33 pm
by volka
If you're using visual studio you can add a "web reference". This will create stub classes that expose the methods of the webservice. You can use those classes almost like any other ("local") class.
see http://support.microsoft.com/kb/818364

Posted: Wed Jul 04, 2007 3:40 am
by Skittlewidth
Thanks Moose and Volka,

I have already created the xml schema and submitted it to the other companies and am now waiting on their solutions.

Creating a web reference in Visual Studio is indeed delightfully easy and I've played about with a few sample web services to see how to access their data and handle errors such as downtime (the data across the 5 products must ideally be kept in sync).

As I mentioned before, the little information I have been passed is that they all agreed to use HTTP-POST for the requests rather than GET - logical because we could be talking about user information for 200+ accounts being sent in a single file on occasions. Am I right in understanding that creating a web reference in Visual Studio creates the appropriate proxy class for the web service I wish to consume? The first tutorials I attempted talked about SOAP but then I played with the same code and random web services without any regard for what protocol the service might have been expecting and it still worked (although they could just all have been soap services - how do I tell?). Or are SOAP and HTTP-POST almost interchangable terms these days?

Anyway, I shall look into HttpWebRequest and HttpWebResponse classes next.
Thanks, I really appreciate the tips!

Posted: Wed Jul 04, 2007 4:45 am
by volka
Skittlewidth wrote:Am I right in understanding that creating a web reference in Visual Studio creates the appropriate proxy class for the web service I wish to consume?
Yes, as long as it "understands" the wsdl descriptor.
Skittlewidth wrote:Or are SOAP and HTTP-POST almost interchangable terms these days?
You can send SOAP requests via http-post (and you probably will). But the two terms are not interchangable. E.g. if you have a html form with method="post" your browser sends a http-post request - no soap involved but still http-post.

Posted: Wed Jul 04, 2007 6:46 am
by Skittlewidth
volka wrote:You can send SOAP requests via http-post (and you probably will). But the two terms are not interchangable. E.g. if you have a html form with method="post" your browser sends a http-post request - no soap involved but still http-post.
Sorry, I meant in Web Service terms. I've since been reminded about XML-RPC and realised that it's probably not the same thing. I think two of these companies have written their systems in PHP and my guess is that they will lean towards XML-RPC rather than SOAP. Both actions involve POST but I think I will have to post to them in different ways.

Posted: Wed Jul 04, 2007 7:32 am
by volka
Then you might be interested in http://www.xml-rpc.net/

Posted: Wed Jul 04, 2007 8:25 am
by Skittlewidth
Yup, bookmarked it already 8)

I'm writing a sample web service in ASP.NET right now as an example of how I think I would like to see it all done. It's wonderfully simple in .NET with all of the SOAP messaging stuff handled by the proxy class. After coding in PHP for so many years I can't help but feel a bit lazy!