Solved

XML ASP.NET (grabbing remote XML)

Posted on 2003-12-03
9
802 Views
Last Modified: 2008-02-20
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
0
Comment
Question by:rossryan
9 Comments
 
LVL 2

Expert Comment

by:DerekStone
ID: 9870771
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
 
LVL 9

Expert Comment

by:malharone
ID: 9870953
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
 

Author Comment

by:rossryan
ID: 9884307
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
 
LVL 9

Accepted Solution

by:
malharone earned 250 total points
ID: 9884390
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rossryan
ID: 9884471
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
 
LVL 9

Expert Comment

by:malharone
ID: 9884494
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
 

Author Comment

by:rossryan
ID: 9884684
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
 
LVL 9

Expert Comment

by:malharone
ID: 9886045
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
 

Expert Comment

by:MorbidVisions
ID: 10498899
Just as an afternote  ups has xml web services also that developers can use
http://www.ec.ups.com  
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now