Solved

xmlhttp object format error

Posted on 2003-10-22
6
255 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:RichardFox
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:rdcpro
Comment Utility
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
0
 

Author Comment

by:RichardFox
Comment Utility
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
0
 
LVL 26

Expert Comment

by:rdcpro
Comment Utility
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
0
IT, Stop Being Called Into Every Meeting

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!

 

Author Comment

by:RichardFox
Comment Utility
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 ------------------->
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 125 total points
Comment Utility
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
0
 

Author Comment

by:RichardFox
Comment Utility
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

6 Experts available now in Live!

Get 1:1 Help Now