Introduction
In this article, we will study how to publish a remote object using IIS, creating an XML document of the remote object and enrichment of an XML document with an XSL file.
Create Remote Object
Firstly, let's start with designing a remote object. The object will have two methods which process Input Output operations.
namespace Remote
{
public class RemoteObject:MarshalByRefObject
{
public FileInfo[] getFiles(string path, string pattern)
{
return new DirectoryInfo(path).GetFiles(pattern);
}
public string[] getDrives()
{
return Environment.GetLogicalDrives();
}
}
}
Create Output File
At this point, the description fields above the methods are more important than the methods themselves (To obtain this fields: Press "/" (AltGr+7) three times). These fields will constitute necessary documentation for our object. When the remote object is compiled, the compiler will create a nested XML document automatically. If we wish, we can enrich the context of nodes in this XML document. For example, the <PARAM>
node does not have a property named type
.
To take output of the description we have prepared for remote object as an XML document, you should check the option "XML documentation file" which is located at the Build|Output menu of properties of your project. Blocks of code should be set as style "Formatted" like this:
Compile the Project with Ctrl+Shift+B. Now we are ready to create a Web application to publish our remote object. Create a Web Project named RemoteObject
and add a reference of our object to the Project.
After adding a reference, Visual Studio will add DLL and XML documents to the bin folder.
Now we add a web config file to Project. With the help of web config file, we will make necessary settings for remote object. In the web config file:
<system.runtime.remoting >
<application >
<service >
<wellknown type="Remote.RemoteObject,remoteSide"
mode="Singleton" objecturi="totalRecall.rem" />
</service >
<channels >
<channel ref="http" />
</channels >
</application >
</system.runtime.remoting >
Create XSLT File
With these settings, remote object will be ready to use after publication of Web Project. But before this, we have to prepare the necessary documentation for people who will use remote object. To do it, add an XSLT file to our application. The aim of this file is to produce a dynamic HTML output for XML document which is defined as a data source. Now let's write the necessary code to file with the XSL extension:
="1.0"="utf-8"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div style="padding:2px;color:#003399;font-family:verdana;width:100%;height:80px;
border:outset gray 1px;background-color:#D4DFFF;">
<table border="0" width="100%" height="100%" cellspacing="0" cellpadding="0">
<tr>
<td style="font-size:12px;">RemoteObject Referans</td>
</tr>
<tr>
<td style="font-size:20px;">
<xsl:value-of select="doc/members/member/@name"/>
</td>
</tr>
<tr>
<td style="font-size:10px;">Language : C#</td>
</tr>
</table>
</div>
<div style="margin:5px 5px 5px 5px;padding:5px 5px 5px 5px;font-family:tahoma;
font-size:14px;">
<xsl:value-of select="doc/members/member/summary"/>
</div>
<xsl:call-template name="methods" />
</xsl:template>
<xsl:template name="methods">
<xsl:for-each select ="doc/members/member">
<xsl:if test="position() > 1">
<div style="font-family:tahoma;font-size:12px;font-weight:bold;color:green;
border-bottom:solid 1px green; height:20px;">
<xsl:value-of select="@name"/>
</div>
<div style="margin:5px 5px 5px 5px;padding:5px 5px 5px 5px;
font-family:tahoma; font-size:12px;">
<xsl:value-of select="summary"/>
</div>
<div style="font-family:tahoma;font-size:12px;font-weight:bold;">
Code
</div>
<div style="margin:15px 15px 15px 15px;padding:5px 5px 5px 5px;
font-family:tahoma;font-size:11px;background-color:#F7F7FF;color:#000066;
border:1px outset gray;width:90%">
<pre>
<xsl:value-of select="code"/>
</pre>
</div>
<div style="font-family:tahoma;font-size:12px;font-weight:bold;">
Parameters
</div>
<table border="1" width="90%" cellspacing="0" cellpadding="1"
style="margin:15px 15px 15px 15px;padding:5px 5px 5px 5px;font-family:tahoma;
font-size:11px;background-color:#F7F7FF;color:#000066;">
<xsl:for-each select="param">
<tr>
<td style="padding:2px;">
<strong>
<xsl:value-of select="@name"/>
</strong> (
<i>
<xsl:value-of select="@type"/>
</i> )
</td>
<td style="padding:2px;">
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</table>
<div style="font-family:tahoma;font-size:12px;font-weight:bold;">
Return Type
</div>
<div style="margin:5px 5px 5px 5px;padding:5px 5px 5px 5px;
font-family:tahoma;font-size:12px;">
<xsl:value-of select="returns"/>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Show Output File
After coding XSLT file, open the Web form Default.aspx. Add an XML control. Match the properties of the control as shown in the image:
The XML control displays the XML data which is specified in DocumentSource
on the Web form with the help of XSL file specified in TransformSource
.
Create Client Application
Next, we should create an application to consume remote object. Design a very simple Windows Form as shown in the image below:
After that, add remote object to Project as a reference. To use remote object, create an app.config file. The necessary code is shown below:
<system.runtime.remoting >
<application >
<channels >
<channel ref="http" port="0" usedefaultcrediantial="true" >
<clientprovider >
<formatter ref="binary" />
</clientprovider >
</channel >
</channels >
<client >
<wellknown type="Remote.RemoteObject,remoteSide"
url="http://localhost:80/webSide/totalRecall.rem" />
</client >
</application >
</system.runtime.remoting>
Finally our code:
private void button1_Click(object sender, EventArgs e)
{
RemotingConfiguration.Configure("WinSide.exe.config", false);
RemoteObject rem = new RemoteObject();
lstFiles.DataSource = rem.getFiles(txtPath.Text, txtPattern.Text);
}
Conclusion
In my opinion, this application is a good sample about the usage of XSLT.
History
- 30th April, 2008: Initial post
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.