Solved

XML ASP.NET (grabbing remote XML)

Posted on 2003-12-03
9
809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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