Solved

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

Posted on 2004-08-25
10
323 Views
Last Modified: 2012-06-27
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"
xmldoc.Load(m_url)

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.
0
Comment
Question by:krose777
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 11899249
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???
(or)
2. Something else?

0
 
LVL 6

Expert Comment

by:zulu_11
ID: 11901841
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
        Try
            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("130.1.7.13"))
            webResp = webReq.GetResponse()
            xmlStream = webResp.GetResponseStream
            strRd = New StreamReader(xmlStream)
            strResp = New StringBuilder()
            strResp.Append(strRd.ReadToEnd())
            strResp = strResp.Replace("&", "&")
            strResp = strResp.Replace("'", "'")
            strResp = strResp.Replace("&", "&")
            Dim objFile As StreamWriter
            objFile = File.CreateText("c:\tempSer.xml")
            objFile.Write(strResp.ToString())
            objFile.Close()
            objFile = Nothing
            MsgBox("done")
            Dim ds As New DataSet()
            ds.ReadXml("c:\tempSer.xml")
            DataGrid1.DataSource = ds
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If Not xmlRd Is Nothing Then
                xmlRd.Close()
                xmlRd = Nothing
            End If
        End Try

have fun...

Zulu
0
 
LVL 2

Author Comment

by:krose777
ID: 11903224
surajguptha,

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?


0
 
LVL 26

Assisted Solution

by:rdcpro
rdcpro earned 250 total points
ID: 11904574
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>"
                  xmlDoc.save(oFileNews.Path)
'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>"
                  xmlDoc.save(oFileHack.Path)
            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"
            Response.Write(xmlDoc.xml)
      else
'      If no error, Write the Response
            ' Set the number of items to show
            If Request.QueryString("XML_News") <> "" Then
                  iNumItems = 26
            Else
                  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
                  xslProc.transform
            sHTML = xslProc.output
            Response.Write sHTML

            If Request.QueryString("XML_Hack") <> "" Then
                  iNumItems = 26
            Else
                  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
                  xslProc.transform
            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
                  xslProc.transform

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

Regards,
Mike Sharp
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 26

Expert Comment

by:rdcpro
ID: 11904603
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:

xmlDoc.save(Response)

Regards,
Mike Sharp

0
 
LVL 21

Expert Comment

by:surajguptha
ID: 11928540
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
0
 
LVL 2

Author Comment

by:krose777
ID: 11934834
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.
0
 
LVL 21

Accepted Solution

by:
surajguptha earned 250 total points
ID: 11938395
In the Windows Application
-------------------------------
XmlDocument xDom= new XmlDocument();
xDom.Load("http://localhost/MikeTesting/WebForm1.aspx");

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

In the Web Application which will call the payservice
------------------------------------------------------------
1)

In the aspx file delete all the html tage except the aspx.cs reference (Important)
example:
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" %>

2)
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
            xDom.Load("http://payservice.com/page.aspx");      
                                //Writes it to the aspx file that will be rendered
            Response.Write(xDom.InnerXml);
      }

This way the Windows Application will call the Web Application and the webapplication will in turn call the payservice and will generate the xml
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 11938404
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

22 Experts available now in Live!

Get 1:1 Help Now