ServerXMLHTTP Object


ServerXMLHTTP Object

In MSXML 3.0, Microsoft introduced a new ServerXMLHTTP object. You should use this object in server-side code, such as in an Active Server Pages (ASP) application. The XMLHTTP component is great for building client-side applications that can be programmed via JavaScript or VBScript inside of Internet Explorer, but it is fundamentally built on the WinInet library and the WinInet library was not designed to support multiple clients . WinInet has some inherent scalability issues and provides features that are not critical for server applications, such as offline support.

The ServerXMLHTTP object's methods and properties are similar to those of the XMLHTTP object. ServerXMLHTTP is backward-compatible with XMLHTTP, so changing your code to use it is as easy as changing the ProgID you pass to your CreateObject function. The ProgID for ServerXMLHTTP is MSXML2.ServerXMLHTTP . ServerXMLHTTP adds four new methods to the collection of standard XMLHTTP methods and properties it inherits. These new methods are getOption , setOption , waitForResponse , and setTimeouts .

The getOption method allows you to determine how ServerXMLHTTP handles Unicode URLs. This method returns one of four values: SXH_OPTION_URL_CODEPAGE (0) , SXH_OPTION_ESPACE_PERCENT_IN_URL (1), SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS (2) , and SXH_OPTION_SELECT_CLIENT_SSL_CERT (3) . The first value means that a client can override the default codepage used to convert a Unicode URL to a single-byte representation. The second value tells ServerXMLHTTP that when it escapes ANSI characters in the URL (for example, a space in a URL becomes %20 ), ServerXMLHTTP should also escape the % character itself. The third and fourth values deal with SSL certificates. You can ignore SSL errors and also tell ServerXMLHTTP which client certificate to use explicitly.

setOption is used in conjunction with getOption . When you call setOption , you pass one of the enumerated values we already discussed for getOption to set that particular option for ServerXMLHTTP .

The waitForResponse method is an interesting feature. When you use XMLHTTP with an asynchronous call, you must continuously check the readyState property to see if the current state of the XMLHTTP object has changed. With waitForResponse , you can specify how long in seconds to wait for the asynchronous send operation to complete. If the send is successful, you will get back a True value. If the send call ends in a timeout, this method will return False . The request will not be aborted ”you can keep waiting for the send operation to complete by simply calling waitForResponse again. The following VBScript example calls a GET on a URL and waits 500 seconds for it to complete:

 Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") oXMLHTTP.Open "GET", "http://<server>/public/myitem.eml", True oXMLHTTP.Send Do While oXMLHTTP.readyState <> 4     oXMLHTTP.waitForResponse 500 Loop 

The setTimeouts method allows you to specify how long ServerXMLHTTP should wait to resolve the domain name , establish the connection to the server, send data, and then receive a response. The values you pass are in milliseconds ”for example, a value of 1000 means 1 second. You can pass 0 to set the timeout to infinite. The following VBScript example waits 1 second for resolving, 2 seconds for connecting, 3 seconds for sending, and 4 seconds for receiving a response:

 Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") oXMLHTTP.setTimeOuts 1000, 2000, 3000, 4000 oXMLHTTP.Open "GET", http://myserver/public/item.eml, false oXMLHTTP.Send 



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net