?
Solved

xmlhttp object format error

Posted on 2003-10-22
6
Medium Priority
?
265 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
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

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 500 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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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