Solved

XML ASP.NET (grabbing remote XML)

Posted on 2003-12-03
9
804 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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
 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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