Loading XML documents from a single point of entry into an XML service

I am using Visual Basic DOT NET program (runs on the user's machine - not a web application) to load an XML document into an XML.XMLDOCUMENT object.  Here is a sample:

Dim xmldoc As New Xml.XmlDocument
dim m_url as string = "theurl.ofmy.xmlservice?abunchofvariables=abunchofvalues"

This works fine.  However, I need to create a SINGLE POINT OF ENTRY into the XML service.  The reason for this is that if everyone that uses my software enters into the XML service by themselves, then I will get charged a per point of entry fee for each user.  

The solution I'm looking for is this.  I would like to do the xmldoc.load(m_url) call to MY webserver:

ie:  xmldoc.load("http://mywebserver.com?abunchofvariables=abunchofvalues")

When I make this request, my web server knows to retreive the XML from theurl.ofmy.xmlserver along with the parameters that I sent with it and to make the resulting XML available as if I had made the call directly to the actual web server that is hosting the XML service.

I can put this service on a Microsoft/ASP server, or a Linux/Perl server.  (those are the only ones that I have available right now, but if I need something special I can deal with that as well.)

For this solution to work for me, I MUST have the ability to populate my Visual Basic XML document object at some point in the process.  

I hope that I have been clear here!  

Thankyou in advance.
Who is Participating?
surajgupthaConnect With a Mentor Commented:
In the Windows Application
XmlDocument xDom= new XmlDocument();

"http://localhost/MikeTesting/WebForm1.aspx" is the URL of myserver.com

In the Web Application which will call the payservice

In the aspx file delete all the html tage except the aspx.cs reference (Important)
If my webpage is webform1.aspx then
only the following line must be present. All other lines that are auto-generated must be deleted

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MikeTesting.WebForm1" %>

In the page load of the cs file

private void Page_Load(object sender, System.EventArgs e)
            XmlDocument xDom= new XmlDocument();
                                //Loads the XML from the paysite
                                //Writes it to the aspx file that will be rendered

This way the Windows Application will call the Web Application and the webapplication will in turn call the payservice and will generate the xml
Let me explain in my own words if i have got your requirement right

1. You have a windows application which loads XML from a pay site
2. If users manually enter the URL that the site has provided you, you will get charged for it (with the assumption that even though your application only calls the URL, the user would somehow trace the URL??!!)
3. So you want a Single point entry to access the service on the pay site using your own webserver to make the request instead of a direct call?

May i know What is the Solution you are expecting ?

1. How to implement the webservice which calls the pay site's service???
2. Something else?

try this,,,this makes a web request from windows application..stores the data to a file and then displays the data  in a datagrid using the file...

       Dim webReq As Net.WebRequest
        Dim webResp As Net.WebResponse
        Dim xmlStream As Stream
        Dim xmlRd As XmlTextReader
        Dim strResp As StringBuilder
        Dim strRd As StreamReader
            webReq = Net.WebRequest.Create("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?cmd=team_lookup_xml&name=overclockers+australia")
            webReq.ContentType = "text/xml"
            'webReq.Proxy.GetProxy(New Uri(""))
            webResp = webReq.GetResponse()
            xmlStream = webResp.GetResponseStream
            strRd = New StreamReader(xmlStream)
            strResp = New StringBuilder()
            strResp = strResp.Replace("&", "&amp;")
            strResp = strResp.Replace("'", "&apos;")
            strResp = strResp.Replace("&amp;amp;", "&amp;")
            Dim objFile As StreamWriter
            objFile = File.CreateText("c:\tempSer.xml")
            objFile = Nothing
            Dim ds As New DataSet()
            DataGrid1.DataSource = ds
        Catch ex As Exception
            If Not xmlRd Is Nothing Then
                xmlRd = Nothing
            End If
        End Try

have fun...

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

krose777Author Commented:

1. Correct
2. Correct - the people who manage the XML service claim that they trace unique users by IP address?  This sounds odd to me, because I dont know what they do for users who are on a dynamic IP.  However, be it as it may, their policy is that for each "point of presence" that enters into their XML service, there is a monthly charge.  Obviously, this puts Windows applications at a big disadvantage to web based applications - you could have a website serving the data to 1 million people, and that is still one point of "entry" according to my rep.  All I need to do to satisfy this requirement is have all the XML calls come THROUGH my website.  I believe that this is a correct.
3. Correct.

Ideally, the solution that I want will make it transparent to my Visual Basic program.  In other words, If there is a way to make the HTTP request to the "pay" xml service to my site, and my site pulls the xml from the pay site and returns it to my VB program as if I called it directly, then that might work.  I would prefer that the solution not involve actually saving a "file" to the web server, because I think that restrictions on my web space might prevent me from doing that from an asp or perl script.  

I am guessing that there is some sort of "networking" type solution where the http request can be passed along to my server which passes it along to the pay service?  I really do not know.

Zulu -
Im not sure I understand your solution.  Which line of code will make the request appear to come from my web server?  Is it the commented out line with the getproxy call?  Can you explain what it does to make the request not come directly from the user's computer/IP?

rdcproConnect With a Mentor Commented:
What you're looking for is federation of web services (or call it aggregation).  It's a very common scenario, especially in web applications, due to cross-domain data access restrictions on browsers.

In VBScript ASP here's how I did this about 4 years ago:

' DIM Variables for Command processing
Dim xmlDoc                  ' XML DOM object
Dim xslDoc                  ' XML DOM object for Stylesheet
Dim xslTemplate            ' Template cache object
Dim xslProc                  ' Rental threaded template processor
Dim sHTML                  ' HTML string variable
Dim sRequest            ' String value of request
Dim bRequest            ' Boolean to flag when XML save needed
Dim iNumItems            ' Number of news items to show from each source
Dim bLoad                  ' Make sure the xml doc was loaded successfully
Dim oFileSys            ' File system object for checking xml modification date
Dim oFileNews            ' object for XML_News file
Dim oFileHack            ' object for XML_Hack file

' Initialize variables
      Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
            xmlDoc.async = false
            xmlDoc.setProperty "ServerHTTPRequest", true
' Check to see how stale the cached news file is
      Set oFileSys = CreateObject("Scripting.FileSystemObject")
      Set oFileNews = oFileSys.GetFile(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xml/XML_News.xml"))
      Set oFileHack = oFileSys.GetFile(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xml/XML_Hack.xml"))
'Response.Write oFileNews.DateLastModified
      if      DateDiff("n",oFileNews.DateLastModified,Now()) > 2 then
'Response.Write "<br>Gotta Revise it<br>"
            sRequest = "http://p.moreover.com/cgi-local/page?index_xml+rss"
'Response.Write "<br>sRequest is:<br>" & sRequest
            bLoad = xmlDoc.load(sRequest)
'Response.Write "<br>bLoad is:<br>" & bLoad
            ' only update the server if the load was successfull
            if bLoad then
'Response.Write "<br>Loaded XML_News<br>"
'Response.Write "<br>Saved<br>"
            end if
            sRequest = "http://xmlhack.com/rss.php"
'Response.Write "<br>sRequest is:<br>" & sRequest
            bLoad = xmlDoc.load(sRequest)
'Response.Write "<br>bLoad XML_Hack is:<br>" & bLoad
            ' only update the server if the load was successfull
            if bLoad then
'Response.Write "<br>Loaded XML_Hack<br>"
            end if
      end if

Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
      xslDoc.async = false
      bLoad = xslDoc.load(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xsl/XML_News.xsl"))
'Response.Write "<br>bLoad Stylsheet is:<br>" & bLoad
Set xslTemplate = Server.CreateObject("MSXML2.XSLTemplate")
      xslTemplate.stylesheet = xslDoc

      if Err.number then
            'Error Handler
            xmlDoc.loadXML("<Error/>")      'Clears out the XML doc for use in error reporting
            'create the Error Attributes
            xmlDoc.documentElement.setAttribute "Err_Number", Err.number
            xmlDoc.documentElement.setAttribute "Err_Description", Err.description
            xmlDoc.documentElement.setAttribute "Err_Source", Err.source
            Response.ContentType = "text/xml"
'      If no error, Write the Response
            ' Set the number of items to show
            If Request.QueryString("XML_News") <> "" Then
                  iNumItems = 26
                  iNumItems = 6
            End If
            sRequest =       oFileNews.Path
'Response.Write "<br>sRequest is:<br>" & sRequest
            bLoad = xmlDoc.load(sRequest)
'Response.Write "<br>bLoad xmlDoc XML_News is:<br>" & bLoad
            set xslProc = xslTemplate.createProcessor
                  xslProc.input = xmlDoc
                  xslProc.addParameter "newsName", "XML_News"
                  xslProc.addParameter "numItems", iNumItems
            sHTML = xslProc.output
            Response.Write sHTML

            If Request.QueryString("XML_Hack") <> "" Then
                  iNumItems = 26
                  iNumItems = 6
            End If
            sRequest =       oFileHack.Path
'Response.Write "<br>sRequest is:<br>" & sRequest
            bLoad = xmlDoc.load(sRequest)
'Response.Write "<br>bLoad xmlDoc XML_Hack is:<br>" & bLoad
            set xslProc = xslTemplate.createProcessor
                  xslProc.input = xmlDoc
                  xslProc.addParameter "newsName", "XML_Hack"
                  xslProc.addParameter "numItems", iNumItems
            sHTML = xslProc.output
            Response.Write sHTML

      end if


This hits two RSS news services, but doesn't do it live.  I cache the feed locally, and only get a new copy of the feed if more than a certain amount of time has passed.  This keeps the response nice and snappy, because there is latency involved if I have to go get a fresh copy.  

There are a couple things I'd change about this, but one is to transform directly to the Response object using IStream, like:

            set xslProc = xslTemplate.createProcessor
                  xslProc.input = xmlDoc
                  <!-- This sends the output to the Response Object directly -->
                  xslProc.output = Response
                  xslProc.addParameter "newsName", "XML_Hack"
                  xslProc.addParameter "numItems", iNumItems

And then remove thes lines:
            sHTML = xslProc.output
            Response.Write sHTML

Mike Sharp
Of course, in your scenario you probably don't need to transform...I got a little carried away.  Just save the XML to the Response like:


Mike Sharp

If we assume that the URL which is used in the windows application can be tracked
Then the URL on your web server which is going to call the Pay Service can also be tracked

If the Window's application is coded in such a way that it calls www.yourserver.com/callpaysite.asp variables=values

if www.yourserver.com/callpaysite.asp variables=values is manually given in the webserver, your webserver will anyway call the pay service and return the XML, eventually charging you.

So i guess something else must be done
krose777Author Commented:
I expect to be charged, i just want all the calls to the pay service to come from myserver.com, not directly from a clients computer.
The above solution is a asp.NET solution to the problem.

Please let me know if this solution is what you want and if it works.
All Courses

From novice to tech pro — start learning today.