Cross-Platform XML Web Services

You've already seen how you can invoke an XML Web service in any browser using HTTP GET and the properly formatted query string. This gives you an idea of how easy it is for a non-.NET client to access an XML Web service. It just has to send the appropriate HTTP request and parse the retrieved XML document.

To test this technique, you can use the Microsoft XML COM library, which includes an XMLHTTP object that can send XML documents over the HTTP channel. This example (shown in Listing 5-4 and illustrated in Figure 5-11) uses Visual Basic 6 and Microsoft XML version 4 (msxml4.dll), but earlier versions will also work.

Listing 5-4 Consuming a .NET XML Web service in Visual Basic 6
 Private Sub Form_Load()     Dim Transfer As XMLHTTP     Set Transfer = New XMLHTTP     ' Call the XML Web Service using HTTP GET.     Transfer.open "GET", _ 
      "http://localhost/WebServices/CustomerDB/CustomerDB.asmx/" & _      GetCustomers", False     Transfer.send     ' Retrieve the XML response.     Dim Doc As DOMDocument     Set Doc = Transfer.responseXML     ' Configure the MSFlexGrid control.     MSFlexGrid1.TextMatrix(0, 0) = "ID"     MSFlexGrid1.TextMatrix(0, 1) = "Name"     MSFlexGrid1.TextMatrix(0, 2) = "Email"     MSFlexGrid1.TextMatrix(0, 3) = "Password"     ' Parse the response.     Dim Child As MSXML2.IXMLDOMNode     For Each Child In Doc.documentElement.childNodes       ' The first node (offset 0) is the ID.       ' The second node (offset 1) is the name.       ' The third node (offset 2) is the email.       ' The fourth node (offset 3) is the password.       MSFlexGrid1.AddItem (Child.childNodes(0).Text & vbTab & _        Child.childNodes(1).Text & vbTab & Child.childNodes(2).Text & _        vbTab & Child.childNodes(3).Text)     Next End Sub 
Figure 5-11. A Visual Basic 6 XML Web service client

graphics/f05dp11.jpg

Ideally, the client will use a slightly more advanced technique and will use SOAP messages. You can send and receive SOAP messages using the XMLHTTP object, but the client will need to shoulder the burden of manually creating the request message and processing the response. If the XML Web service changes, the client must also adapt. However, most platforms include more sophisticated tools that enable you to send SOAP messages using a higher-level abstraction and even create proxy classes by analyzing WSDL documents. Some examples include the following:

  • Microsoft's SOAP Toolkit, which works with the previous generation of Visual Studio products (such as Visual Basic and C++)

  • IBM's Web Service Development Kit

  • Oracle's Web Integration Development Language

  • Sun Microsystems's Sun ONE (Open Net Environment) offering, which now supports Web services written in the Java language

  • Perl's SOAP::Lite kit, which provides basic SOAP functionality



Microsoft. NET Distributed Applications(c) Integrating XML Web Services and. NET Remoting
MicrosoftВ® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting (Pro-Developer)
ISBN: 0735619336
EAN: 2147483647
Year: 2005
Pages: 174

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