XML/Web Services 100 Interview Questions - Part 2 of 5
Preparing for an interview? Or just want to refresh your XML skills? Here are 100 questions on XML and related technologies.
The Part I in this series presented 20 questions to assess the basic concepts. Now, the Part II focuses on XML implementation questions specific to Microsoft platform. In part III we'll highlight 20 Java XML questions, part IV on Web services concepts, and finally part V on some advanced design/implementation questions.
Compiled By: |
perfectxml.com Team |
Last Updated: |
January 21, 2003 |
Level: |
Intermediate |
Platform: |
Questions specific to XML/Web serivces implementation on Microsoft platform. |
Please note that the answers/opinions expressed in this article are solely based on our experience. If you disagree or have any questions, we welcome your comments. Please email your comments us at .
1. How would you process XML data/document in an ASP page, that is in a non-.NET, classic Active Server Page (ASP)?
The best approach would be to use the latest Microsoft XML Core Services (MSXML) COM object.
Here is an example of an ASP page (using JavaScript) that loads the following XML document on the server using MSXML DOM, updates the value of a particular node, and saves the updated XML file. The idea is to update the value of Hits node each time the ASP page is called.
AdCounts.xml
<?xml version="1.0"?>
<Ads>
<Advertiser ID="1">
<BannerURL>SomeImage.gif</BannerURL>
<Hits>0</Hits>
</Advertiser>
</Ads> TestMSXML.asp
<script runat="server" language="javascript">
//Disable caching on the client
Response.CacheControl = "no-cache";
Response.AddHeader ("Pragma", "no-cache");
Response.Expires = -1;
//Create DOM Object
var xmlDOM = new ActiveXObject("MSXML2.DOMDocument.4.0");
//Set properties
xmlDOM.async = false;
xmlDOM.validateOnParse = false;
xmlDOM.resolveExternals = false;
//Load the XML file
var bLoadResult = xmlDOM.load(Server.MapPath("AdCounts.xml"))
if(bLoadResult)
{
//Document load succeeded, select Hits node and update it
var nodeHits = xmlDOM.selectSingleNode("/Ads/Advertiser[@ID='1']/Hits");
if(nodeHits)
{
nodeHits.dataType = "int";
nodeHits.nodeTypedValue = nodeHits.nodeTypedValue + 1;
Response.Write("Hits: " + nodeHits.nodeTypedValue);
}
//Save the updated document
xmlDOM.save(xmlDOM.url);
}
else
{
//failed to load XML document. Do error handling using parseError.
}
</script>
|
2. What is required to make sure that the client-side XSLT transformation works inside Microsoft Internet Explorer?
If the stylesheets are applied using the script code on the client side, installing atleast MSXML 3.0 in either replace or side-by-side mode is sufficient. If the stylesheet processing instruction (<?xml-stylesheet type="text/xsl" href="somefile.xsl"?>) is used to associate the XSLT stylesheet with the XML document, MSXML 3.0 should be installed in the replace mode, so that Internet Explorer uses the version 3.0 while applying the stylesheet.
The reason we have to do this is because earlier version of Internet Explorer browser included the MSXML parser that supported XSL working draft standard (and not the current XSLT recommendation). One of the notable differences in these two is in the use of the namespace: as per the XSL working draft, the stylesheets used xmlns:xsl="http://www.w3.org/TR/WD-xsl" namespace declaration, however the XSLT recommendation suggests that stylesheets should use xmlns:xsl="http://www.w3.org/1999/XSL/Transform" namespace declaration. Internet Explorer 6.0 ships MSXML 3.0 SP2, which gets installed in replace mode, and hence the XSLT stylesheets should work right out-of-the-box with Internet Explorer 6.0. There is a tool available on MSDN that lets convert old XSL stylesheets into XSLT stylesheets. The two other important points to remember are that no version of Internet Explorer yet (as of Jan 19, 2003) ships the latest MSXML 4.0 (SP1) parser; and that MSXML 4.0 removed the support for old XSL standard (and namespace), it only supports the XSLT specification.
Let's look at an example of an XML document, an XSLT stylesheet, apply the stylesheet using the client-side script and finally use the XSLT processing instruction and let Internet Explorer automagically apply the stylesheet (it internally uses MSXML to do that).
sites.xml
<?xml version="1.0" encoding="UTF-8"?>
<Sites>
<News>http://www.cnn.com</News>
<Tech>https://perfectxml.com</Tech>
<Dev>http://msdn.Microsoft.com</Dev>
</Sites> sites.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform">
<xslt:output method="html" encoding="iso-8859-1" />
<xslt:template match="/">
<xslt:apply-templates select="Sites" />
</xslt:template>
<xslt:template match="Sites">
<xslt:for-each select="child::node()">
<ul>
<li>
<xslt:value-of select="name(.)" />:
<a href="{.}"><xslt:value-of select="." /></a>
</li>
</ul>
</xslt:for-each>
</xslt:template>
</xslt:stylesheet> sites.html: Applying the above XSLT stylesheet using the client-side JScript code:
<html>
<head><title>Sites</title></head>
<body><h1>Sites</h1><div id="favSites"></div>
<script language="JScript">
<!--
try
{
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
var xslDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.validateOnParse = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("sites.xml");
xslDoc.async = false;
xslDoc.validateOnParse = false;
xslDoc.resolveExternals = false;
xslDoc.load("sites.xsl");
favSites.innerHTML = xmlDoc.transformNode(xslDoc);
}
catch(e)
{
//Error Handling
}
//-->
</script>
</body>
</html> sites2.xml: Associating the XSLT stylesheet with the XML document using the processing instruction:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sites.xsl" ?>
<Sites>
<News>http://www.cnn.com</News>
<Tech>https://perfectxml.com</Tech>
<Dev>http://msdn.Microsoft.com</Dev>
</Sites> The result of applying the XSLT stylesheet (sites.xsl) on the XML document (either using client-side JScript or by letting Internet Explorer apply the stylesheet when we include the XSLT processing instruction in the XML document), the output would be a unordered list of sites as shown below:
- Dev: http://msdn.Microsoft.com
|
3. Briefly discuss the XML support in the .NET Framework.
One of the top features in the .NET Framework is the level of XML/Web services integration and support.
The .NET Framework provides extensive support to work with XML and Web services, and at the same time it makes use of XML technologies at various places inside the Framework and the language specifications. For example, the configuration files in .NET Framework now use the XML syntax. The popular web.config file (for ASP.NET Web sites) is an XML file. While writing the C# .NET code the special ///-style comments can be used to generate the code documentation in XML or HTML format. The .NET Framework supports creating and consuming XML Web services. The Visual Studio .NET further simplifies these tasks. The .NET XML Web services, in addition to supporting SOAP method of invocation, also support GET and POST access to the Web service methods. ASP.NET Web services automagically generates the Web methods documentation (based on the attribute values set in the code), and provide a test environment for Web methods.
As far as processing XML is concerned, the primary namespace that is used is System.Xml. This namespace provides the classes that support DOM Level 1 and Level 2 (XmlDocument), XPath (XmlNavigator), XML validation (XmlValidatingReader), generating and reading XML (using XmlTextWriter and XmlTextReader), and transformation using XslTransform.
The ADO.NET System.Data.DataSet class supports writing disonnected recordset in the XML format, and reading XML to populate the DataSet instance. XML Schemas (XSD) alongwith the DataSet class can be used to work with the strongly typed DataSet that allow us to access tables and columns by name, instead of using collection-based methods (that is, with this we can write CustomerDS.OrderID instead of CustomerDS["OrderID"]). In addition to the improved readability, typed DataSet offers many other benefits, such as code-completion in Visual Studio .NET, type-checking at compile time, and so on.
Finally, it is important to mention about the XmlDataDocument class. XmlDataDocument class derives from XmlDocument and also contains a member of type DataSet; allowing us to load either relational data or XML data, and then manipulate it using the W3C DOM. |
4. What is Microsoft BizTalk Server, and what is its application?
Microsoft BizTalk Server, a member of .NET Enterprise Servers suite, provides organizations with the server, tools, adapters, and vertical accelerators needed to integrate and automate their business. It is the premier Microsoft solution for EAI (Enterprise Application Integration), B2B, and BPA (Business Process Automation).
BizTalk Server allows integrating application via the exchange of structured messages. BizTalk Server includes parsers and serializers for XML, flat files (delimited or positional), and EDI (ANSI X12 or UN/EDIFACT) documents; and supports HTTP, HTTPS, SMTP, MSMQ, DCOM, IBM MQSeries, and file transports.
BizTalk Server is made up of two services: The messaging service (handles the passing of messages between two applications), and the XLANG Scheduler (handles the Orchestration). XLANG is the XML vocabulary used to describe the Orchestration process. Orchestration refers to the environment for creating and running distributed business processes.
To integrate BizTalk Server with application from other companies such as SAP, J.D. Edwards, and PeopleSoft; and to support a broad spectrum of business scenarios and industries, Microsoft provides various Adapters and Accelerators. See http://www.microsoft.com/biztalk for details. Microsoft also offers BizTalk Adapter for Web Services (at no charge to BizTalk Server 2002 users) that can be used to expose e-business functions over the Internet. |
5. Does .NET Framework support SAX?
It is a fact that .NET Framework contains excellent support for industry standards such as XML, XML Namespaces, XSLT, XPath, XSD, SOAP, and DOM; however, .NET does not support SAX.
SAX is a streaming, push-based, event-based, forward-only, read-only API to parse XML documents. The .NET Framework on the other hand, supports a better, pull-based (but still forward-only and read-only) API to parse XML document (in addition to DOM implementation). This API is offered via the classes derived from the XmlReader class in the System.Xml namespace. These classes offer the benefits of SAX (well-suited for parsing large XML documents as do not require memory/processing resources, etc.), and still is much simpler to use (unlike SAX, which requires more work from the application that uses the API). |
6. Is it possible to use MSXML inside a .NET application? If yes, under what scenarios it would be helpful to use MSXML instead of the Framework provided classes from the System.Xml namespace?
The .NET Framework designers certainly thought about the interoperability with the existing non-.NET (especially COM) applications. The result of this thought is the support for accessing COM components inside the .NET Framework code. The .NET code accessing COM objects makes use of a proxy, known as runtime callable wrapper or RCW, whose job is to marshal calls and data between a .NET client and a COM object.
As MSXML is an automation-enabled COM object, it is certainly possible to use MSXML from within .NET code.
Some of the situations where it will make more sense to use MSXML rather than .NET provided System.Xml classes, include: rapidly porting existing code (that uses MSXML), to work with SAX2, to work with XSLT stylesheet that uses older scripting languages (msxsl:script), to work with old XSL stylesheets written using XSL working draft, and so on. Finally, as of today (Jan 19, 2003) the latest MSXML version (4.0 SP1) XSLT transformation engine performs better when compared to .NET System.Xml.XslTransform class; in such situation also it would be useful to MSXML XSLT engine. |
7. While creating an Intranet Web site, it is required that one of the pages periodically refreshes part of the page (instead of loading the entire page). The Web page needs to get the updated data from the server. All the departments have Internet Explorer 6.0 installed. How would you do implement periodically refreshing part of (let's say a particular section on) the page?
Internet Explorer 6.0 ships MSXML 3.0 (SP2). MSXML includes a class known as XMLHTTP that can be used to send GET/POST request to any URL over HTTP and receive the response. This class can be used to inside the client-side JScript code to send the request to the server, get the updated data and refresh the part of the page using DHTML.
The following sample ASP page contains the client-side JScript code that makes use of MSXML XMLHTTP to POST a SOAP request to a XML Web service, get the response back and refresh the result on the page. Just for the sake of example, we POST a request to the delayed stock quote Web service available on XMethods.net site, every 15 seconds:
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
'Print the current date and time
'Just to illustrate that the entier page is not refreshed
Response.Write "Date & Time: " & Now()
%>
<br><br>MSFT Stock Value (Will refresh every 15 seconds).<div id="divTime"></div> <br><div id="msftStock"></div>
<br><a href="javascript:" onClick="stopTimer();">Stop Refreshing</a>
<script language="JScript">
<!--
var iTimerID;
function stopTimer()
{
window.clearInterval(iTimerID);
}
function getCurrentStockValue(tickerSymbol)
{
try
{
var strSOAPReq = "<SOAP-ENV:Envelope " +
"xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' " +
"xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/1999/XMLSchema'> " +
"<SOAP-ENV:Body> " +
"<ns1:getQuote " +
" xmlns:ns1='urn:xmethods-delayed-quotes' " +
" SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> " +
" <symbol xsi:type='xsd:string'>" + tickerSymbol + "</symbol> " +
"</ns1:getQuote> " +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>"
var objXH = new ActiveXObject("MSXML2.XMLHTTP.3.0");
objXH.open ("POST", "http://66.28.98.121:9090/soap", false);
objXH.setRequestHeader("SOAPAction", "urn:xmethods-delayed-quotes#getQuote");
objXH.send(strSOAPReq);
//alert(objXH.status + " " + objXH.statusText);
if(objXH.status == 200)
{
return(objXH.responseXML.selectSingleNode("//Result").nodeTypedValue);
}
else
{
alert(objXH.status + " " + objXH.statusText);
}
}
catch(e)
{
//Error handling
}
}
function refreshQuote()
{
//alert("Refreshing the stock quote");
divTime.innerHTML = "<i>updated: " + Date() + "</i>";
msftStock.innerHTML = "<b>" + getCurrentStockValue("MSFT") + "</b>";
if(iTimerID)
window.clearInterval(iTimerID);
iTimerID = window.setInterval("refreshQuote()", 15000);
}
refreshQuote();
//-->
</script>
|
8. What are XML Data Islands? And what is their application?
Internet Explorer 5 introduced a new concept of embedding chunks of XML data inside the Web HTML page, and then accessing that XML data either from the client-side script or directly binding that data to the HTML controls such as HTML tables. These are known as XML Data Islands and sometimes turn out useful in scenarios such as in avoiding the round-trip to the server. The XML data is enclosed between the special tags (<XML ID="someid">.....</XML>). Click here for more details. |
9. Describe the XML support in ADO 2.7.
ADO is still the most commonly used data access API on Microsoft platform. The version 2.5 introduced the support for XML in this API, by allowing us to save the Recordset data as XML, or reading XML into the Recordset object.
The following Visual Basic code illustrates saving the relational data (Recordset) into the XML format. Remember to add reference (Project|Reference) to ADO type library.
Dim objADORS As New ADODB.Recordset
objADORS.Open "SELECT * FROM [Customers]", _
"PROVIDER=SQLOLEDB.1;SERVER=.;UID=sa;PWD=;DATABASE=Northwind"
objADORS.Save "c:\ADOCustomers.xml", adPersistXML
objADORS.Close
Set objADORS = Nothing Similar to the Save, the Open method also supports working with XML (to load Recordset from the ADO-persisted XML).
This support (to persist ADO Recordset as XML or load the XML into the Recordset) is available to all the OLE DB providers. Special support is added for SQL Server 2000 into the SQLOLEDB provider and the SQLXMLOLEDB provider. These providers support extended properties (specifically for the Command object) to offer SQL Server 2000's native XML features accessible to ADO clients. The following sample ASP page illustrates these special properties.
This sample ASP page works with SQL Server 2000 and ADO 2.6 or higher. It makes use of special Command object dialect that allows running SELECT... FOR XML queries available natively in SQL Server 2000. The following ASP page runs the SELECT... FOR XML on the Customers tables in the Northwind sample database, sets special Command object properties to indicate that the output should go to the ASP Response stream, the result of SELECT... FOR XML queries should have NWContacts as the root element, and then to apply NWContacts.xsl stylesheet on the generated XML. The output of the following ASP page would be HTML table listing CompanyName, ContactName, and Phone from the Customers table.
<%
Option Explicit
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Const adExecuteStream = 1024
Dim adoConn
Dim adoCommand
Set adoConn = Server.CreateObject("ADODB.Connection")
adoConn.Open "PROVIDER=SQLOLEDB;SERVER=.;UID=sa;PWD=;DATABASE=Northwind"
Set adoCommand = Server.CreateObject("ADODB.Command")
Set adoCommand.ActiveConnection = adoConn
adoCommand.Dialect = "{C8B522D7-5CF3-11CE-ADE5-00AA0044773D}"
adoCommand.CommandText = _
"SELECT [CompanyName],[ContactName],[Phone] FROM [Customers] FOR XML RAW"
adoCommand.Properties("Output Stream") = Response
adoCommand.Properties("XML Root") = "NWContacts"
adoCommand.Properties("XSL") = Server.MapPath("NWContacts.xsl")
adoCommand.Execute ,,adExecuteStream
adoConn.Close
Set adoConn = Nothing
%> The ASP page uses the following XSLT stylesheet (NWContacts.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform">
<xslt:output method="html" encoding="UTF-16" />
<xslt:template match="/">
<xslt:apply-templates select="NWContacts" />
</xslt:template>
<xslt:template match="NWContacts">
<table width="100%" border="1">
<xslt:for-each select="row">
<tr>
<td><xslt:value-of select="@CompanyName" /></td>
<td><xslt:value-of select="@ContactName" /></td>
<td><xslt:value-of select="@Phone" /></td>
</tr>
</xslt:for-each>
</table>
</xslt:template>
</xslt:stylesheet>
|
10. Describe the application of OPENXML function in SQL Server 2000.
SQL Server 2000 introduced a new function named OPENXML, as part of XML features made available in this release. The OPENXML function allows accessing XML data as if it were a relational rowset. It provides a tabular (rowset) view of in-memory representation of an XML document. Technically, OPENXML is a rowset provider similar to a table or a view; hence it can be used wherever a table or a view is used. For instance, you can use OPENXML with SELECT or SELECT INTO statements, to work on an XML document that is retained in memory. Click here for more details. |
11. Does .NET support writing the RPC-type XML Web services as per section 7 in the SOAP specification?
Yes, the .NET Framework supports writing RPC-type XML Web services. The two attribute classes SoapRpcMethod and SoapRpcService are used for this purpose. Let's look at an example:
Start Notepad and write (or copy-paste) the following C# code:
<%@ WebService Language="C#" class="MathsWebSvc" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace="SomeTestURI")]
public class MathsWebSvc : WebService {
[ WebMethod(Description="Add two numbers.") ]
public int AddTwoNos(int iA, int iB) {
return iA+iB;
}
} Save the above file under some virtual directory or Web site as TestRPC.asmx. Browse to the TestRPC.asmx and click on Service Description link to view the WSDL file. By default, the Framework creates document-style (and not the RPC-style) Web service. Keep this window open and then update the asmx Web service file as highlighted below:
<%@ WebService Language="C#" class="MathsWebSvc" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace="SomeTestURI")]
public class MathsWebSvc : WebService {
[ SoapRpcMethod(Action="SomeActionURI",
RequestNamespace="SomeRequestURL",
RequestElementName="AddTwoNosRequest",
ResponseNamespace="SomeResponseURI",
ResponseElementName="AddTwoNosResponse")]
[ WebMethod(Description="Add two numbers.") ]
public int AddTwoNos(int iA, int iB) {
return iA+iB;
}
} The above lines of code add the SoapRpcMethod attribute to the AddTwoNos Web method, making it a RPC-style SOAP method. Save the above file, open a new browser window, and browse to the WSDL file. Closely notice the differences in the WSDL file - specifically, at the top, on how the schema is changed, search for <soap:operation on the WSDL pages and notice the change in the value of the style attribute. Note that, we have just changed one Web method to be of type RPC-style, the binding (search for soap:binding in the WSDL pages) is still document style.
Add the SoapRpcService attribute as shown below, save the .asmx file, open the WSDL (by clicking on Service Description after browsing to the asmx page), and notice the change in the soap:binding element (style attribute).
<%@ WebService Language="C#" class="MathsWebSvc" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
[SoapRpcService()]
[WebService(Namespace="SomeTestURI")]
public class MathsWebSvc : WebService {
[ SoapRpcMethod(Action="SomeActionURI",
RequestNamespace="SomeRequestURL",
RequestElementName="AddTwoNosRequest",
ResponseNamespace="SomeResponseURI",
ResponseElementName="AddTwoNosResponse")]
[ WebMethod(Description="Add two numbers.") ]
public int AddTwoNos(int iA, int iB) {
return iA+iB;
}
}
|
12. What are Updategrams, and what is their application?
The notion of Updategrams was introduced in SQL Server 2000 XML Web Release 1 (or SQLXML 1). An XML document, that contains special tags, to indicate the original data and the updated data, is termed as an Updategram, and it allows modifying (inserting, updating, and deleting) SQL Server 2000 table(s) data.
SQLXML defines a namespace (urn:schemas-microsoft-com:xml-updategram) and a set of specific tags in this namespace (such as sync, before, after, and so on) that are used inside an Updategram XML document. The <sync> tag wraps one or more <before> and <after> element pairs, and executes the database updates as a single transaction.
If <after> block is specified without a corresponding <before> tag or with empty <before> tag, insert operation is performed. If <before> block is specified without or with empty <after> block, delete operation is performed. If both, <before>, and corresponding <after> blocks are present, it results in execution of an update statement. An Updategram can have multiple database operations, executed in one or more database transactions. Annotated XSD schemas can be associated with the Updategrams to indicate how the elements and attributes in the Updategram XML map to the database table and columns, and most importantly to specify the primary key - foreign key relationship.
Updategrams, being a special case SQLXML template files, can be executed over HTTP by sending a GET request for the Updategram XML file (or browsing to it), or with the HTTP POST operation (posting to the virtual root), or from ADO application by using the special Command dialect, or through the SQLXML 3.0 .NET managed classes.
Example of a SQLXML Updategram: Updates the Author table in the Pubs sample SQL Server 2000 database. The value of contract column is changed to 0 for author with au_id=172-32-1176. Note that the following updategram XML file is placed under physical directory that is configured as a virtual name of type template under a SQLXML IIS virtual directory that points to the Pubs sample database. This configuration is performed using the SQLXML IIS Support tool.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram<.b>">
<updg:sync >
<updg:before>
<Authors au_id="172-32-1176" />
</updg:before>
<updg:after>
<Authors contract="0" />
</updg:after>
</updg:sync>
</ROOT>
|
13. What is DiffGram?
ADO.NET introduced the DataSet class to support the disconnected, distributed data-access scenarios. With DataSet, the data retrieved from the database is cached in-memory, in addition to the constraints and relationships among the tables. When the ADO.NET DataSet is serialized as XML (for example, when returning a DataSet from an ASP.NET XML Web service method), the XML format used for DataSet serialization is known as DiffGram. Like Updategrams, DiffGrams also contains the tags that specify the original and new state of data. SQLXML and .NET Managed classes can be used to execute DiffGrams to perform the database updates, however there are many things that are supported by Updategrams and not by DiffGrams (ability to pass parameters being one example). |
14. Is it possible to access a XML Web service from a client-side script, without using MSXML (XMLHTTP class), assuming all clients have Microsoft® Internet Explorer 5.0 or higher.
Absolutely! With IE 5.0 or higher, WebService behavior can be used along with DHTML client-side JScript or VBScript to invoke the XML Web service.
Following HTML page uses the WebService behavior and the client-side JScript code to access AmazonBestSelling Web service to find out best selling Pocket PC on Amazon.com.
<html>
<head><title>Find Best Selling Pocket PC</title>
<script language="JScript">
<!--
function init()
{
amazonSvc.useService
("http://www.PerfectXML.net/WebServices/AmazonBestSelling/amazon.asmx","bestSelling");
}
function showResults()
{
//alert(event.result.value.xml);
amazonSvc.innerHTML = "Best selling Pocket PC is: <b>" +
event.result.value.selectSingleNode("//product/title").nodeTypedValue +
"</b>";
}
//-->
</script>
</head>
<body onload="init();">
<button
onclick='amazonSvc.bestSelling.callService("ByKeyword","Pocket PC","electronics");'>
Find Best Selling Pocket PC
</button>
<div id="amazonSvc" style="behavior:url(webservice.htc)" onresult="showResults();">
</div>
</body>
</html> If the XML Web service being accessed is on some different server than the Web page containing the WebService behavior, Internet Explorer will show a warning message box informing the user that Web page is/will trying to access information from some other site.
For above HTML page to work, you'll need webservice.htc in the same (virtual) directory/Web site as the HTML page.
Click here for more information on WebService Behavior.
|
15. Is there any way to rapidly turn dispatchable COM object interfaces into the Web service methods?
Sure! The Microsoft SOAP Toolkit includes WSDL Generator wizard that can be used to selectively expose the IDispatch-derived interface methods in a COM DLL, as Web service methods. The wizard creates the WSDL, WSML files and the ISAPI or ASP listener. |
16. Does .NET support one-way Web service operations? Does Microsoft SOAP Toolkit support one-way Web service operations?
Yes, .NET framework does support one-way messages. To set a void method as one-way operation, set the OneWay property to true on SoapDocumentMethodAttribute or on SoapRpcMethodAttribute attribute. In such cases, the Web service client is intending to just send some notification to the server and not expect any response. The server in such cases returns 202 Accepted HTTP response to the client. And there will be no output message in the WSDL file for such methods. The support for one-way Web service operations was also added in the latest SOAP Toolkit 3.0 release. |
17. Does .NET support validating XML documents against DTDs?
Yes, in addition to XDR and XSD schema validation, .NET continues to support the DTD to validate the XML documents. The System.Xml namespace contains a class named XmlValidatingReader that can be used to validate the XML documents. |
18. Explain how to process XML documents using DOM in an ASP.NET page?
The System.Xml namespace class XmlDocument can be used to load and process XML documents in an ASP.NET page. For example, following ASP.NET code snippet loads web.config (an XML-formatted file) and outputs values of the compilation - defaultLanguage and authentication - mode attributes.
using System.Xml;
. . . .
. . . .
XmlDocument WebConfigHelper = new XmlDocument();
WebConfigHelper.Load(Server.MapPath("Web.Config"));
string defLang =
WebConfigHelper.SelectSingleNode("//compilation/@defaultLanguage").Value.ToString();
string authMode =
WebConfigHelper.SelectSingleNode("//authentication/@mode").Value.ToString();
Response.Output.Write("Language: {0} Authentication Mode: {1}",
defLang, authMode);
|
19. Describe the basic difference between XMLHTTP and ServerXMLHTTP?
XMLHTTP, a COM-wrapper around the classing WinInet library is designed to be used on the client-side to send HTTP requests to the server. Whereas, ServerXMLHTTP was introduced in MSXML 3.0 to support server-safe HTTP access. ServerXMLHTTP is based on WinHTTP, a new HTTP protocol stack, designed to be used on the server-side to send HTTP requests. |
20. Briefly explain the limitations and benefits of applying XSLT transformation on the server versus on the client.
Applying the XSLT stylesheet on the server aids in building the browser-independent Web application (and support any other client for that matter, for example WAP browser). We don’t have to worry about if the transformation would work on the client or not (because of issues such as legacy XSL implementation in earlier versions of Internet Explorer). We can always use the latest MSXML parser (which may be providing better XSLT transformation performance) to apply the transformation on the server and send the transformed results to the client. The limitations of applying the stylesheet on the server include the load added on the server. If the transformation is applied on the client, the CPU cycles and other resources required to apply the transformation are offloaded on the client (instead of adding the load on the server), and hence improved server performance. Also, the client can cache the stylesheet and save some network bandwidth. Finally, on the client side, different views of the same data can be presented, by applying different stylesheet on the same data (without reloading the page). |
Stay tuned for next set of 20 questions focused on Java and XML!
|
|