XML ASP.NET (grabbing remote XML)

I need to grab a remote XML file generated by a shipping partner's website. Specifically, Yellow Freight (www.myyellow.com).

How do I grab this data (called from within a .NET application)? When the page is loaded, the code needs to open a connection to Yellow Freight, grab the file, extract the needed parameters. How do I do this?

Thanks,
Ryan
rossryanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DerekStoneCommented:
If the XML file is accessible via a Web server the System.Net.WebClient.DownloadFile() method will retrieve the file for you.

Example:

Imports System.Net

Dim wc As WebClient = New WebClient()
wc.DownloadFile("http://www.myyellow.com/file.xml", "C:\temp.xml")
0
malharoneCommented:
this is a general function .. for any type of webpage/file download


    Public Function readHtmlPage(ByVal url As String, ByVal param As String) As String
        Dim result As String = ""
        Dim strPost As String = param
        Dim myWriter As StreamWriter

        Dim objRequest As HttpWebRequest = WebRequest.Create(url)
        objRequest.Method = "POST"
        objRequest.ContentLength = strPost.Length
        objRequest.ContentType = "application/x-www-form-urlencoded"

        Try
            myWriter = New StreamWriter(objRequest.GetRequestStream())
            myWriter.Write(strPost)
        Catch e As Exception
            Return e.Message
        Finally
            myWriter.Close()
        End Try

        Dim objResponse As HttpWebResponse = objRequest.GetResponse()
        Dim sr As StreamReader
        sr = New StreamReader(objResponse.GetResponseStream())
        result = sr.ReadToEnd()
        sr.Close()

        Return result
    End Function
0
rossryanAuthor Commented:
Hmm. Is there a way to grab the file and keep it in memory, as opposed to grabbing it, saving it to the hd, and then loading it? The data contained within the file is not needed after the transaction is completed (as the freight quotes (very large products) will change on an hourly basis)).

Cheers,
Ryan
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

malharoneCommented:
well .. if you keep the file in "memory" then you can't really access it via "c:\...". but to answer your question, this is the simplified version


   private sr As StreamReader

    Public sub readHtmlPage(ByVal url As String, ByVal param As String)
        Dim result As String = ""
        Dim strPost As String = param

        Dim objRequest As HttpWebRequest = WebRequest.Create(url)
        objRequest.Method = "POST"
        objRequest.ContentLength = strPost.Length
        objRequest.ContentType = "application/x-www-form-urlencoded"

        Dim objResponse As HttpWebResponse = objRequest.GetResponse()
        sr = New StreamReader(objResponse.GetResponseStream())
    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rossryanAuthor Commented:
Very nice. I am working on a .NET application, and this code will allow the checkout portion to grab the latest rates, parse them, then present them to the user. Values are saved to the SQL database after confirmation.

Thanks,
Ryan
0
malharoneCommented:
glad to be of help! you're lucky you're getting your data in XML.. one of our vendors who USED to publish data in XML (year 2000) changed their format to excel in late 2002. Now they've changed to to PDF!!! :< which is impossible to parse since the PDF writer they've used non-standard encryptions and encodings. ARGH!!
for some reason, they're going backwords!!
anyways ... good luck w/ your app.
0
rossryanAuthor Commented:
Hehe, I know how much fun that is. Our company uses Fedex, UPS, Airborne, Yellow Freight, etc. The xml in question comes from Yellow Freight (myyellow.com).

The server (MS Commerce Server) is a great idea, especially paired with the solution sites they give you. It's all SQL, XML, and ASP.NET based, which is why my eyes lit up when I saw one of our shippers used XML. However, two things may be said: 1.) the code MS gives you is, at best, half finished. It's like they put half the features in, and a lot of really cool ones (multiple ship-to addresses, targeted advertising, predictor for popular products, I could go on), but they forgot or left out some of the really important ones (a decent shipping system, a payment system!).

The way they currently have it setup, you have to manually enter the shipping costs (in one of three categories: by subtotal, by weight, or by quantity). I mean, really, really, really basic: if productweight_ = 30 lbs, then charge $40. That basic. Forget different shipping rates for different states (or countries, for that matter). Oh yeah, the site does multiple languages (they even included the translator .dlls, so a few of our customers are shopping in German)). There is no payment system to speak of, in that a customer can purchase a product, enter their cc, etc. However, we have no way of getting that information! I have to create the system from scratch (grabbing a bunch of values from the DB).

2.) Fedex and UPS are going to die. UPS has its rates in excel files (actually about 200 of them), and Fedex is going down the PDF route.

Couple this with our companies almost religious following of the published shipping rates, and I feel like screaming by the end of the day. So I have to create a few new tables for Fedex and UPS, add in code for the XML from Yellow Freight and hope that nothing breaks there, then I have to add a few more tables, with code to override the other shipping options, because on certain items, the shipping costs are averaged across the US, and they need to match the printed catalog. That and no one would pay $2000 to ship one of our products across the US, whereas locally they can get it delivered for $200.

Sorry for the rant, but I just can't stand it. I've been working on this project for 7 months now, and all I want is for it to be finished. I talk to the MS engineers on a daily basis, trying to cleanup the code (*cough*their code*cough*). When it works, it works wonderfully, when it doesn't it realllllllllllllly doesn't.

Aright, good night everybody,

Ryan  
0
malharoneCommented:
yeah rossryan .. i totally feel your pain ... on my case, building a stupid PDF parser wasn't fun either ... spend almost a month to get it ready -- quick & dirty .. then spent next 4 months building a generic parser & document builder using interactive regular expression ... all it did was take the data from PDF and convert into the specified XML file format !!
good night to you all ... i'm in California .. it's about 5 pm .. gotta hit the painful commute again!!
0
MorbidVisionsCommented:
Just as an afternote  ups has xml web services also that developers can use
http://www.ec.ups.com   
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.