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

rdcproCommented:
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
RichardFoxAuthor Commented:
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
rdcproCommented:
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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

RichardFoxAuthor Commented:
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 ------------------->
rdcproCommented:
I think Select defaults to a shallow traversal.  If you want a deep traversal, you need to specify the Scope:

SCOPE('deep traversal of "http://myserver/public2"')

Regards,
Mike Sharp

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
RichardFoxAuthor Commented:
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
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.