Solved

SENDING XML FILE TO A SERVER**URGENT**

Posted on 2003-12-12
12
573 Views
Last Modified: 2008-03-04
Hey,

My project is to create a banner on our companies website which actually allows our
customers to check the availability of a domain name of their choice.The domain name that they enter has to be embedded in an xml file Our hosting services have given us an API which actually defines the DTD's to be used ,the url of their server and the specific port that they want us send the xml file too.The reply that whether the domain name is available or not will also be sent to us as an xml file(the DTD of which is specified to) which I need to then parse and display the result to our user as to whether the domain name that they have entered is available or not.

I was able to generate the xml file dynamically based on the users input.The only problem is that I am unable to send it to the target server as desired.

Here is the header and an example of a xml file that the www.networksolutions.com(one with whom we register domains) people want us to use :

The following sample HTTP request illustrates the actual content that a client sends to the
Network Solutions server to accomplish a task (in this case a name availability request). This
example includes the header information section followed by the respective content information
section.

POST /invoke/Network Solutions.transactionproxy.Inbound/XMLAvailableProxy HTTP/1.0
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: text/xml
Content-length: 265


<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
<RequestHeader>
<VERSION_3_4></VERSION_3_4>
<Authentication>
<PartnerID>123</PartnerID>
<PartnerPassword>partner</PartnerPassword>
</Authentication>
<Comments></Comments>
</RequestHeader>
<Body>
<VerifyDomainName>example.com</VerifyDomainName>
</Body>
</AvailableRequest>


I tried to use MSXML core services but was unsuccesful.

*******************************************************************
************Here is the code that I am using which actually builds xml file dynamically***
*******************************************************************

<%@ LANGUAGE="VBScript" %>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

  Sub SetValues()
    Dim domain
    Dim ext

    domain=txtDomain
    ext=cmbExt
  End Sub
</SCRIPT>

<HTML>

<HEAD>
<title>New Page 1</title>

</script>

</head>

<body>

<%

   Dim test

      If (Request.Form.Item("txtDomain") = "") then

      //domain = Request.Form ("txtDomain")
      //ext = Request.Form ("cmbExt")

      //Response.Write (domain & "." & ext & "<br><br>")
%>


<p>&nbsp;</p>
<form method="GET" action="copyofenter_domain_name.asp" name="domain_search">
  <p>enter domain name</p>
  <p><input type="text" name="txtDomain" size="20"><select size="1" name="cmbExt">
    <option selected>.com</option>
    <option>.net</option>
  </select></p>
  <p><input type="submit" value="Submit" name="B1"></p>
</form>
<p>&nbsp;</p>

<%      Else

      ' Get input from the user.  THe Request.Form() method
      ' can be used to get data from HTML forms submitted via
      ' the POST method.

      domain = Request.Form ("txtDomain")
      ext = Request.Form ("cmbExt")
      test = domain & ext

      'Response.Write ("The domain name selected is " & domain & ext)
      response.write (test)

'****************** XML FILE CREATION ******************

' create a file system object
set fso = createobject("scripting.filesystemobject")

' create the text file  - true will overwrite any previous files

' Writes the db output to a .xml file in the same directory
Set act = fso.CreateTextFile(server.mappath("customer.xml"), true)

' All non repetitive xml on top goes here
act.WriteLine("<?xml version=""1.0"" encoding='UTF-8'?>")

act.WriteLine("<AvailableRequest>")
act.WriteLine("<RequestHeader>")
act.writeline("<VERSION_3_5></VERSION_3_5>")
act.writeline("<Authentication>")
act.writeline("<PartnerID>18191849</PartnerID>")
act.writeline("<PartnerPassword>23176</PartnerPassword>")
act.writeline("</Authentication>")
act.writeline("<Comments></Comments>")
act.writeline("</RequestHeader>")
act.writeline("<Body>")
act.writeline("<VerifyDomainName>" & test & "</VerifyDomainName>")
act.writeline("</Body>")

' All non repetitive xml on bottom goes here
act.WriteLine("</AvailableRequest>")

' close the object (xml)
act.close

' Writes a link to the newly created xml document in the browser
response.write "<a href='customer.xml'>Customer</a> (.xml) has been created <br>"
response.write "on  " & now() & "<br>"

End If

%>

</body>
</html>


I tried to use MSXML core services but was unsuccesful.

What I am looking for is actual example of code that actually sends the xml file
to the server,recieve the reply(xml file) and then parse it to get the specific answer.

Appreciate your help!
0
Comment
Question by:jd311
[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
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 9

Expert Comment

by:sparkplug
ID: 9929170
Hi,

In ASP you can use ServerXMLHTTP to post XML data to an external server

Set oXMLData = Server.CreateObject("MSXML2.DOMDocument")
oXMLData.async = false
If Not oXMLData.LoadXML("<root><data value="test" /></root>") Then
   Set oErr = xml.parseError
   sErrMsg = "XML Parsing Error. File: " & oErr.url & "  Reason : " & oErr.reason & " Line: " & oErr.line & ", Character: " & oErr.linepos & ", Text: " & oErr.srcText
  Err.Raise 999, sErrMsg
End If

Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

oXMLHTTP.open "POST", "http://someserver/respond.asp", false      
oXMLHTTP.send(oXMLData)    ' Send the XML.

Response.ContentType = "text/xml";
If Not oXMLHTTP.status = 200 Then
 Response.Write "<Error>Could not get XML data.</Error>"
End If      

Response.Write (oXMLHTTP.responseXML.xml)

For more information on ServerXMLHTTP look here: http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_obj_iserverxmlhttprequest_5115.asp

Hope this helps,

>S'Plug<



0
 
LVL 26

Expert Comment

by:rdcpro
ID: 9929335
I can't see why you're writing the XML to the filesystem...don't you need to post it to the Netsol server?  There is a ServerXMLHTTP Request object that is used for this purpose.  The user POSTs the domain to your server, and you package up the request, and send it to Net Sol.  Then you parse the response and put the result in your response back to the client.  Here's an example (written in JScript, so you'll have to translate it, if you really want to use VBScript.

Regards,
Mike Sharp

/*

This code assumes that this XML template is already on the filesystem.  
If not, build it using DOM methods

<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
    <RequestHeader>
        <VERSION_3_4/>
        <Authentication>
            <PartnerID>123</PartnerID>
            <PartnerPassword></PartnerPassword>
        </Authentication>
        <Comments/>
    </RequestHeader>
    <Body>
        <VerifyDomainName></VerifyDomainName>
    </Body>
</AvailableRequest>


*/

var xmlDoc = new ActiveXObject("Msxml2.DomDocument")
xmlDoc.async=true;

try
{
    xmlDoc.load(Server.MapPath("template.xml");
}
catch(e)
{
    //Handle error in case of problem with load
}
// now set the XML doc properties
var oNode = xmlDoc.selectSingleNode("AvailableRequest/Body/VerifyDomainName");
oNode.text = "domaintocheck.com";
var oNode = xmlDoc.selectSingleNode("AvailableRequest/RequestHeader/Authentication/PartnerPassword");
oNode.text = "mypassword";


var xmlHttp = new ActiveXObject("Msxml2.ServerXMLHTTP");
try
{
    xmlHttp.Open("GET", s, false, xmlLogin.value, xmlPass.value);
}
catch(e)
{
    // Put your error handling code here
}

// Set request headers as required
xmlHttp.setRequestHeader("Content-type", "text/xml");

//  This POSTs the XML
xmlHttp.Send(xmlDoc);

if (!xmlHttp.responseXML.documentElement)
{
    //Some servers don't send the contenttype correctly, and even
    //though they send back good XML, the xmlHttp object fails to parse it
    //especially where the URL doesn't end in .xml
    //Serializing the XML isn't the best approach, but it works in those cases.
    //one must be careful of encoding in this case.
    xmlDoc.loadXML(xmlHttp.responseText);
}
else
{
    xmlDoc.load(xmlHttp.responseXML);

}  


// Now xmlDoc contains the response, but xmlHttp.responseXML is
// also a fully parsed XML DOM object, and this last step isn't always necessary.
// I put it here to show how to hand servers that do not set contenttype correctly.

0
 
LVL 9

Expert Comment

by:sparkplug
ID: 9929373
Nice bit of extra detail there, Mike. But wouldn't you want to do a POST instead of a GET?

;-)

>S'Plug<
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 26

Expert Comment

by:rdcpro
ID: 9929427
Uh, yeah.  That's what I "GET" for cutting and pasting!

Also, since I pasted this from somewhere else, this whole line is messed up, because I didn't specify the URL, either.  It should be something like:

    sUrl = //Path to the service endpoint
    xmlHttp.Open("POST", sUrl, false );


Glad someone is around to keep me honest!  ;^)


Regards,
Mike Sharp
0
 
LVL 9

Expert Comment

by:sparkplug
ID: 9930061
.... oh and just to make sure you're extra honest... ;-)

surely xmlDoc.load(xmlHttp.responseXML) would be have to be xmlDoc.load(xmlHttp.responseXML.xml) although I would have thought that if the content type is wrong then xmlHttp.responseXML would not be valid anyway. Probably better to check xmlHttp.parseError.errorCode.

>S'Plug<
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 9930361
No, you want to use IStream, so that encoding is preserved.  the .xml property serializes the XML, but does not provide a BOM, and that's burned me before.  Now, if you really wanted to do that, you'd have to use loadXML. But since responseXML is a DomDocument object by itself, a simple assignment would also work:

var newXMLDoc = xmlHttp.responseXML

If the server has provided well-formed XML, but for some reason the xmlHttpResponseXML.documentElement doesn't exist, you use the responseText property.  My thoughts on the "why" of it are based on my observations during times when it would happen to me.  It's hard to tell what the XMLHTTPRequest object is thinking sometimes.

Regards,
Mike Sharp
0
 

Author Comment

by:jd311
ID: 9982582
Hello S'Plug,

Thank you for your posting .

I used your code but had one problem .
Your code has the following line

If Not oXMLData.LoadXML("<root><data value="test" /></root>") Then

How do I change this line so that my XML file(the one posted above) is loaded.

I wrote ("<AvailableRequest></AvailableRequest>") but the output says
XML file not available.

Help is appreciated.

jd311

Waiting for your reply.
0
 
LVL 9

Expert Comment

by:sparkplug
ID: 9984163
Strange, this should work.

s="<AvailableRequest><RequestHeader><VERSION_3_4></VERSION_3_4><Authentication><PartnerID>123</PartnerID><PartnerPassword>partner</PartnerPassword></Authentication><Comments></Comments></RequestHeader><Body><VerifyDomainName>example.com</VerifyDomainName></Body></AvailableRequest>"
If Not oXMLData.LoadXML(s) Then
  .....

Are you sure that you are calling LoadXML() and not just Load()? This seems like it might be the case from your error message "XML file not available". The Load() method is used to load the XML from a file whereas LoadXML() loads from a string. See http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_mth_hn_1nho.asp?frame=true

>S'Plug<
0
 

Author Comment

by:jd311
ID: 9984913
Hi S'Plug

Yes I did try your idea.
I am using LoadXML().

I got the following error.

  msxml4.dll (0x80070005)
  Access is denied

Help appreciated.

jd311.

**points increased**
0
 

Author Comment

by:jd311
ID: 9987101
Hi,

I played around a bit and was able to overcome the "Access is denied" error.

Now I am getting the following error

"<Error>Could not get XML data</Error>"

What could be the possible reasons for this.

Also while writing the url where I need to POST should I write
"https://www.networksolutions.com/"  OR "http://www.networksolutions.com/"
(Note the http & https)

If I use http it gives me "Could not get XML data" while if I use https connection gets timed out

Please help.

jd311
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12623464
PAQed with points refunded (350)

modulo
Community Support Moderator
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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. 
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

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