SENDING XML FILE TO A SERVER**URGENT**

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!
jd311Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sparkplugCommented:
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<



rdcproCommented:
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.

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

;-)

>S'Plug<
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

rdcproCommented:
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
sparkplugCommented:
.... 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<
rdcproCommented:
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
jd311Author Commented:
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.
sparkplugCommented:
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<
jd311Author Commented:
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**
jd311Author Commented:
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
moduloCommented:
PAQed with points refunded (350)

modulo
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.