[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

XML ASP.NET (grabbing remote XML)

Posted on 2003-12-03
9
Medium Priority
?
812 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 9

Accepted Solution

by:
malharone earned 1000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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