Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

vba - Differences between XMLHTTP and ServerXMLHTTP

I'm trying to write an Excel add-in that can get data from a web service into Excel.

To use it, the user just needs to type a function name provided by the add-in. I found two articles implementing HTTP requests in VBA: XMLHTTP and ServerXMLHTTP.

I have difficulty with using them. I don't know which one to use. What are the differences between XMLHTTP and ServerXMLHTTP?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Davuz,

Both Tim and Jay provide excellent context and succinct comments. I will simply add a bit and try to give some context.

In essence, the XMLHTTP Object is used to create an XMLHttpRequest, which is used to requisition data from a website/webserver/web service. See the wikipedia link for further details: http://en.wikipedia.org/wiki/XMLHttpRequest

In general, XMLHTTP is general used when communicating as a client to a server - such as when you use an application to make a request to a webservice. the XMLHTTP Object is also used for various client-focused methods of transfer, such as File Transfer Protocol (FTP), url caching and other useful tools. In short, the XMLHTTP Object is used to make a request to a server of some sort and request something of interest to the client, whether it is access to a server via a FTP connection, a series of files from a repository, or a webservice for processing data from the client.

By contrast, the ServerXMLHTTP is intended for communicating between servers, to applications (clients) and for processing requests from clients. While the ServerXMLHTTP Object keeps the state active - meaning that the information sent/received to/from a destination is retained for future data transactions in the current connection - it also does not actively support certain XMLHTTP functions, such as "URL caching, auto-discovery of proxy servers, HTTP/1.1 chunking, offline support, and support for Gopher and FTP protocols" for the http client stack used by the ServerXMLHTTP object.

From a technical standpoint, the XMLHTTP Object uses WinInet (Windows Internet Explorer) for its functionality, while the ServerXMLHTTP Object uses a client stack. The WinInet dll is the backbone of the Windows internet protocol management, and the dll is used for handling HTTP, HTTPS, FTP and similar requests.

By contrast, when the ServerXMLHTTP Object creates a new client http stack - which is an essence a separate "session" of a HTTP client. The use of a separate session means that multiple instances of the ServerXMLHTTP Object may be active at any given time - depending on memory and availability of socket connections.

So, in a nutshell - in addition to the information from the comments above, the XMLHTTP Object is often used to request information and use it in some way, usually as a client. Similarly useful but often differently used, the ServerXMLHTTP Object may be used to request data, to send data or even to pass received to another application to another application in a relatively efficient manner. This is often used for business applications that require realtime responses, or for providing data to clients given a series of requests, perhaps with conditions built into those requests - and much, much more.

Hopefully that sheds some light on the differences between the two. There is much more to be found when reading SO questions/answers on using specific pieces of XMLHTTP type requests, as well as deeper research into MSDN and other sites providing documentation on internet/XMLHTTPRequest specific materials for VB, VBA and Microsoft Office.

Let me know if that helps or if you have other questions/thoughts,

~JOL


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...