Solved

SENDING XML FILE TO A SERVER**URGENT**

Posted on 2003-12-12
12
561 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
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 9

Expert Comment

by:sparkplug
Comment Utility
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
Comment Utility
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
Comment Utility
Nice bit of extra detail there, Mike. But wouldn't you want to do a POST instead of a GET?

;-)

>S'Plug<
0
 
LVL 26

Expert Comment

by:rdcpro
Comment Utility
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
Comment Utility
.... 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 26

Expert Comment

by:rdcpro
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (350)

modulo
Community Support Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

9 Experts available now in Live!

Get 1:1 Help Now