Solved

xmlhttp object format error

Posted on 2003-10-22
6
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 9603152
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
ID: 9606441
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
ID: 9609289
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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:RichardFox
ID: 9614066
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
ID: 9630169
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
ID: 9633997
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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