Link to home
Start Free TrialLog in
Avatar of RichardFox
RichardFox

asked on

xmlhttp object format error

This code, from a short knowledgebase article at Microsoft (http://support.microsoft.com/?kbid=259849)
 
<%@ LANGUAGE=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Simple SEARCH</TITLE>
</HEAD>
<BODY>
<%

   Response.Write("----begin----" + "<br>")
   set doc = createobject("microsoft.xmldom")
   set docback = createobject("microsoft.xmldom")
   dim strURL
   strURL = "http://172.16.10.21/public/"
   set pi = doc.createProcessingInstruction("xml","version=""1.0""")
   doc.appendChild pi

   set node = doc.createNode(1,"searchrequest","DAV:")
   set doc.documentElement = node

   set node2 = doc.createNode(1,"sql","DAV:")
   node.appendChild node2
   set query = doc.createTextNode("select ""DAV:displayname"" from """ & strURL & """ WHERE CONTAINS('""and""')")

   node2.appendChild query

   set req = createobject("microsoft.xmlhttp")
   req.open "SEARCH", strURL, false, "ACS-TEST\Richard.Fox", "rf23$%67"
   req.setrequestheader "Translate", "f"
   req.setrequestheader "Content-Type", "text/xml"
   req.setrequestheader "Depth", "0"
   req.send doc
   Response.Write("Error, status=" & req.status & " " & req.statusText)

   set docback = req.responseXML
   docback.Save "c:\temp\docback.xml"

   Dim objNodeList

   Set objNodeList = docback.getElementsByTagName("a:displayname")
   For i = 0 To (objNodeList.length -1)
     Set objNode = objNodeList.nextNode
     Response.Write(objNode.Text & "<hr>")
   Next

   Response.Write("----end----" + "<br>")

%>
</BODY>
</HTML>

Is giving me the xml request error:

Error, status=422 Unprocessable Entity

Can someone help me out why? This is all part of providing a capability to search the exchange public folders using the full-text index. Please see the knowledgebase article for full details of the script.

Thanks,

Rich
Avatar of rdcpro
rdcpro
Flag of United States of America image

I see several problems with that code snippet.

This:
   set doc = createobject("microsoft.xmldom")
is the old MSXML version 2.0 parser.  You should use at least MSXML 3:
   set doc = createobject("Msxml2.DomDocument")

Also--and I'm amazed that Microsoft has published this snippet--the bit is definitely NOT recommended for server side use. They have several KB articles on this issue:
   set req = createobject("microsoft.xmlhttp")
You should only use the Server-safe version, which came with MSXML 3 and higher:
   set req = createobject("Msxml2.ServerXMLHTTP")


I'd also write the XML document that's being sent, just to make sure it's being created as you expect.  And, if whatever is returned from the request isn't parseable, you need to see what the responseText is.  I'd do something like:

  Response.write Server.HTMLEncode(doc.xml)
  req.send doc
  Response.write req.getAllResponseHeaders()
  Response.write Server.HTMLEncode(req.responseText)


Post what that response is, and we'll take a closer look.  

Regards,
Mike Sharp
Avatar of RichardFox
RichardFox

ASKER

Mike,
I made the changes you suggested and here is the output:

----begin----
<?xml version="1.0"?> <searchrequest xmlns="DAV:"><sql>select "DAV:displayname" from "http://172.16.10.21/public/" WHERE CONTAINS('"and"')</sql></searchrequest> Server: Microsoft-IIS/5.0 Date: Thu, 23 Oct 2003 13:20:24 GMT Content-Type: text/html Content-Length: 152 MS-WebStorage: 6.0.6249 <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> </HEAD> <body><h2>HTTP/1.0 422 Unprocessable Entity</h2></body></HTML>Error, status=422 Unprocessable Entity
----end----

Thanks,
Rich
This means that you have a valid XML body in a SEARCH, but an unsupported or unimplemented query operator.  

Sounds like an exchange configuration issue, or else the query is outdated and needs a newer syntax.  The example code you got from microsoft is quite old...

Regards,
Mike Sharp
You were right, I had to work on my syntax and xml document is now:

<?xml version="1.0"?> <searchrequest xmlns="DAV:"><sql>select "DAV:displayname" from "http://myserver/public/docs" WHERE CONTAINS(*,'"fox"')</sql></searchrequest>


 My full-text indexing is still not working though.  CONTAINS does not appear to be doing a deep traversal of the public folder tree and does not return the right set of data. Can anyone help me out with the full-text searching?

Many thanks
Rich

<!------------------- snip, rename as whatever.asp  -------------------->
<%@ LANGUAGE=VBScript %>
<HTML>
<HEAD>
<TITLE>Simple SEARCH</TITLE>
</HEAD>
<BODY>
<%

   Response.Write("----begin----" + "<br>")
   set doc = createobject("Msxml2.DomDocument")
   set docback = createobject("Msxml2.DomDocument")

   dim strURL
   dim strURLFolder
   strURL       = "http://myserver/public"
   strURLFolder = "http://myserver/public/SEARCH/MyFolder"
   set pi = doc.createProcessingInstruction("xml","version=""1.0""")
   doc.appendChild pi

   set node = doc.createNode(1,"searchrequest","DAV:")
   set doc.documentElement = node

   set node2 = doc.createNode(1,"sql","DAV:")
   node.appendChild node2
   'set query = doc.createTextNode("select ""DAV:displayname"" from """ & strURL & """ WHERE CONTAINS(*,'""searchword""')")
   node2.appendChild query

   set req = createobject("Msxml2.ServerXMLHTTP")
   req.open "SEARCH", strURL, false, "DOM\USER", "PASS"
   req.setrequestheader "Translate", "f"
   req.setrequestheader "Content-Type", "text/xml"
   req.setrequestheader "Depth", "0"

   Response.write Server.HTMLEncode(doc.xml)
   req.send doc


   set docback = req.responseXML
   docback.Save "c:\temp\docback.xml"

   Response.Write("<br><br>")
      ' An error occurred on the server.
      If req.status >= 500 Then
               Response.Write( "Status: " & req.status )
               Response.Write( "<br>" )
               Response.Write( "Status text: An error occurred on the server." )

      ' successful.
      ElseIf req.status = 207 Then
               Response.Write( "Status: " & req.status )
               Response.Write( "<br>" )
               Response.Write( "Status text: " & req.statustext )
               Response.Write( "<br>" )
               Response.Write( "Command successful.<br><br>" )

      Else
               'Response.write req.getAllResponseHeaders()
               Response.Write( "<br>ResponseText:<br>" )
               Response.write Server.HTMLEncode(req.responseText)
               Response.Write( "<br>" )
               Response.Write( "<br>Status: " & req.status )
               Response.Write( "<br>" )
               Response.Write( "<br>Status text: " & req.statustext )
      End If

   Dim objNodeList

   'Typically the DAV namespace get the 'a' prefix.
   'If you are specifying multiple properties in a search,
   'examine the returned XML beforehand to determine prefixes
   'for your code.

   Set objNodeList = docback.getElementsByTagName("a:displayname")
   For i = 0 To (objNodeList.length -1)
     Set objNode = objNodeList.nextNode
     Response.Write(objNode.Text & "<hr>")
   Next

   Response.Write("<br>----end----" + "<br>")

      %>
</BODY>
</HTML>
<!------------------- snip ------------------->
ASKER CERTIFIED SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, I discovered this too! And I noticed that you wrote "public2". It seems - and this is only a suspicion, not a certainty - that deep traversals are not allowed on the default public folder store for a server. If one creates a second public folder store, with virtual website, then it can be deeply traversed as you say.

This is quite idiotic, I think. What if you want to search your public folder store? You must first replicate to another public store, run the full-text indexing on that one, and do searches there?

I have a $100 support request in to MS for a definitive answer on this. I will post the results of the inquiry here.

Thanks very much for your continued attention and research, Mike, it is greatly appreciated.

Rich