<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Sayed Y. Hashimi</title>
  <link rel="alternate" type="text/html" href="http://www.sayedhashimi.com/" />
  <link rel="self" href="http://www.sayedhashimi.com/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2007-11-09T12:22:14.9635000-08:00</updated>
  <author>
    <name>Sayed Y. Hashimi</name>
  </author>
  <subtitle>Smart Client, ClickOnce, .NET, Java</subtitle>
  <id>http://www.sayedhashimi.com/</id>
  <generator uri="http://www.dasblog.net" version="1.8.5223.2">DasBlog</generator>
  <entry>
    <title>MTOM with Axis2 version 1.3</title>
    <link rel="alternate" type="text/html" href="http://www.sayedhashimi.com/PermaLink,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx" />
    <id>http://www.sayedhashimi.com/PermaLink,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</id>
    <published>2007-11-09T12:22:14.9635000-08:00</published>
    <updated>2007-11-09T12:22:14.9635000-08:00</updated>
    <category term="Web Services" label="Web Services" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <font size="2">
          <p>
      A step-by-step guide to writing a web service which supports MTOM and a web service
      client to call it. The example assumes a Windows environment and Eclipse as the development
      environment. 
   </p>
          <b>
            <p>
      Setup the Development Environment
   </p>
          </b>
          <p>
      1. Download Tomcat version 5.5 from 
   </p>
        </font>
        <a href="http://tomcat.apache.org/download-55.cgi">
          <u>
            <font color="#0000ff" size="2">http://tomcat.apache.org/download-55.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. Set the JAVA_HOME environment variable to the Java JDK directory. Note that you
      have to set the variable to the JDK and not the JRE install folder.
   </p>
          <p>
      3. Run startup.bat from the Tomcat distribution bin directory to make sure Tomcat
      will run. If all is good, run shutdown.bat from the bin directory to stop the Tomcat
      server.
   </p>
          <p>
      4. Download Axis2 version 1.3 (
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/download/1_3/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/download/1_3/download.cgi
   </font>
          </u>
        </a>
        <font size="2">)
   <p>
      a. Download the Standard Distribution and the WAR distribution.
   </p><p>
      5. Copy the axis2.war file from the WAR distribution in step 4 to the webapps folder
      under Tomcat. Start Tomcat by running startup.bat. If Tomcat was able to consume the
      war file, then you should be able to browse to 
   </p></font>
        <a href="http://localhost:8080/axis2/">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/
   </font>
          </u>
        </a>
        <font size="2"> to see the Axis2 web application default page.
   <p>
      6. Upon startup, Tomcat unpacked the axis2.war file. Have a look at the axis2.xml
      configuration file within axis2\WEB-INF\conf\ folder.
   </p><p>
      7. The axis2.xml file contains the administrator username and password for axis2 administration.
      By default the username and password to admin and axis2, respectively. You can modify
      this by changing the values and restarting Tomcat.
   </p><p>
      8. Point your browser to the axis2 web application and choose the Administration link. 
   </p></font>
        <a href="http://localhost:8080/axis2/axis2-admin/login">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/axis2-admin/login
   </font>
          </u>
        </a>
        <font size="2">. Type in the username and password to access the admin
   console.
   <p>
      9. So far we have Tomcat and Axis2 up and running. To make this exercise less painful,
      we should also download TCPMon so we can view the SOAP message we create. Download
      TCPMon from: 
   </p></font>
        <a href="http://ws.apache.org/commons/tcpmon/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/commons/tcpmon/download.cgi
   </font>
          </u>
        </a>
        <font size="2">. This utility is very cool and easy to use. Before
   you start TCPMon (by running tcpmon.bat from the build), have a look at the user guide. </font>
        <a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html">
          <u>
            <font color="#0000ff" size="2">http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
   </font>
          </u>
        </a>
        <font size="2">
          <b>
            <p>
      Create MTOM Enabled Web Service
   </p>
          </b>
          <p>
      1. Create a new Java Project in Eclipse. Name the project TestMTOM.
   </p>
          <p>
      2. Add the axis2 jar files to the classpath. The axis2 jar files are within the lib
      directory of the axis2 standard distribution.
   </p>
          <p>
      3. Create a new class named TestService within a package named com.test. Paste the
      following for the class implementation.
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      package
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.File;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileNotFoundException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileOutputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.IOException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.InputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.OutputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> javax.activation.DataHandler;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMElement;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMText;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      public
   </p>
          </font>
        </b>
        <font face="Courier New" color="#000000" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">class
   </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> TestService </font>
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"C:\\HOLD\\att.pdf"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> receiveMTOM(OMElement element) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception 
   <p>
      {
   </p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"received
   request..."</font>
        <font face="Courier New" size="2">);
   <p></p><p>
      OMText binaryNode = (OMText) (element.getFirstElement()).getFirstOMChild();
   </p><p>
      binaryNode.setOptimize(
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   <p>
      DataHandler dh = (DataHandler) binaryNode.getDataHandler();
   </p><p>
      InputStream is = dh.getInputStream();
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] buf = <i>readFully</i>(is);
   <p><i>writeOutput</i>(buf);
   </p><p></p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"done
   writing output file."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> writeOutput(</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] buf)</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> IOException
   <p>
      {
   </p><p>
      File of = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> File(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2">(of.exists())
   <p>
      {
   </p><p>
      of.delete();
   </p><p>
      }
   </p><p>
      of.createNewFile();
   </p><p><i>setContents</i>(
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> File(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">),buf);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> setContents(File aFile, </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] aContents) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> FileNotFoundException, IOException
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (aFile == </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   should not be null."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.exists())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> FileNotFoundException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   does not exist: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.isFile())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"Should
   not be a directory: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.canWrite())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   cannot be written: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">declared</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">here</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">only</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">make</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">visible</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">finally</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">clause;</font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">generic</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">reference
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      OutputStream output = 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">try
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
      output = 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> FileOutputStream(aFile);
   <p>
      output.write(aContents);
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">finally
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">flush</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">and</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">close</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">both</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">"output"</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">and</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">its</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">underlying</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">FileWriter
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (output != </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      output.close();
   </p><p>
      }
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] readFully(InputStream is) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> IOException
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> size = 10000;
   <p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">Offset</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#7f7f9f" size="2">-</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">how</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">much</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">read
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> off = 0;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> got;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] ret = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[size];
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">try
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">while
   </font>
        </b>
        <font face="Courier New" size="2"> (</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      {
   </p><p>
      got = is.read(ret, off, size - off);
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">End</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">of</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">stream
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (got == -1)
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">break
   </font>
        </b>
        <font face="Courier New" size="2">;
   <p>
      off += got;
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (off == size)
   <p>
      {
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">If</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">read</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">the</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">end</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">of</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">our</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">buffer,
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">enlarge</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">it.
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      size *= 2;
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] tmp = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[size];
   <p>
      System.<i>arraycopy</i>(ret, 0, tmp, 0, off);
   </p><p>
      ret = tmp;
   </p><p>
      }
   </p><p>
      }
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">finally
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2">(is!=</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)is.close();
   <p>
      }
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">If</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">got</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">a</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">bigger</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">buffer</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">than</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">need,</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">resize</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">it</font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (off != size)
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] tmp = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[off];
   <p>
      System.<i>arraycopy</i>(ret, 0, tmp, 0, off);
   </p><p>
      ret = tmp;
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">return
   </font>
        </b>
        <font face="Courier New" size="2"> ret;
   <p>
      }
   </p><p>
      }
   </p></font>
        <font size="2">
          <p>
      The receiveMTOM() method expects an 
   </p>
        </font>
        <font face="Courier New" size="2">OMElement</font>
        <font face="Courier New" size="2">,
   which then contains the binary file. The method simply pulls the binary file out of
   the SOAP message and saves it to the local file system. The file is identified by
   the OUTPUT_FILE static variable. Note that we have to 
   <p></p></font>
        <font face="Courier New" size="2">binaryNode.setOptimize(</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   </font>
        <font size="2">
          <p>
      prior to calling the getDataHandler() method. 
   </p>
          <p>
      4. The service implementation is done. Now we have to create a service.xml file. To
      do that, first create a folder under the root of the project and name it META-INF.
      Within this folder, create an xml file and name it services.xml. Paste the following
      into that file.
   </p>
        </font>
        <font face="Courier New" color="#008080" size="2">
          <p>
      &lt;
   </p>
        </font>
        <font face="Courier New" color="#3f7f7f" size="2">service </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" color="#000000" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"TestService"</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">description</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
      This service is to get the running Axis version
   </p>
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">description</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"ServiceClass"</font>
        <font face="Courier New" color="#008080" size="2">&gt;</font>
        <font face="Courier New" size="2">com.test.TestService</font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"enableMTOM"</font>
        <font face="Courier New" color="#008080" size="2">&gt;</font>
        <font face="Courier New" size="2">true</font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">operation </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"receiveMTOM"</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">messageReceiver </font>
        <font face="Courier New" color="#7f007f" size="2">class</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"org.apache.axis2.rpc.receivers.RPCMessageReceiver" </font>
        <font face="Courier New" color="#008080" size="2">/&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">operation</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   <p>
      &lt;/
   </p></font>
        <font face="Courier New" color="#3f7f7f" size="2">service</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
      To enable MTOM, we have to add a parameter for the service called enableMTOM and set
      its value to true. Note that MTOM is disabled by default.
   </p>
          <p>
      5. The next thing we have to do is package the service as a jar file but with a "aar"
      extension. You can do this several ways, but the easiest approach is to just use Eclipse's
      Export functionality. 
   </p>
          <p>
      6. Once you have the aar file, copy it under the axis2 deployment within Tomcat. This
      would be at TOMCAT_INSTALL\webapps\axis2\WEB-INF\services\
   </p>
          <p>
      7. Restart Tomcat.
   </p>
        </font>
        <font size="2">
          <b>
            <p>
      Create MTOM enabled Web Service Client
   </p>
          </b>
          <p>
      1. Before we can call the service, we need a proxy to the web service. Assuming Tomcat
      is running, browse to the following URL. 
   </p>
        </font>
        <a href="http://localhost:8080/axis2/services/TestService?wsdl">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/services/TestService?wsdl
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. To create the proxy, save the WSDL file to the bin directory of the Axis2 installation.
      Name the file TestService.wsdl. Note that within this directory, you'll also have
      the WSDL2Java.bat file that we need to use to create the web service proxy.
   </p>
          <p>
      3. After you save the WSDL file, open a command prompt and execute 
   </p>
          <p>
      WSDL2JAVA -uri TestService.wsdl
   </p>
          <p>
      This should create the proxy files with a folder name src. 
   </p>
          <p>
      4. Now we need to create a java project within Eclipse for the web service client.
      Create a new Project and name it TestMTOMClient. 
   </p>
          <p>
      5. Add the Axis2 jar files to the classpath. 
   </p>
          <p>
      6. Copy the src folder from step 3 under the TestMTOMClient project and refresh the
      project in Eclipse.
   </p>
          <p>
      7. Now create a class to execute the web service. Name the class TestClient and paste
      the following in its place.
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      package
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.File;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileInputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.IOException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.InputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> junit.framework.TestCase;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMAbstractFactory;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMElement;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMFactory;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMNamespace;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMText;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axis2.Constants;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axis2.util.<strike>Base64</strike>;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test.TestServiceStub.ReceiveMTOM;</font>
          <p>
            <font color="#000000">
            </font> 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      public
   </p>
          </font>
        </b>
        <font face="Courier New" color="#000000" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">class
   </font>
        </b>
        <font face="Courier New" color="#000000" size="2"> TestClient </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">extends
   </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> TestCase</font>
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">EPR
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"</font>
        <a href="http://localhost:9080/axis2/services/TestService">
          <u>
            <font face="Courier New" color="#0000ff" size="2">http://localhost:9080/axis2/services/TestService
   </font>
          </u>
        </a>
        <font face="Courier New" color="#2a00ff" size="2">"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">INPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"C:\\HOLD\\small.pdf"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> main(String[] args) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception
   <p>
      {
   </p><p></p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> testMTOM()</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception
   <p>
      {
   </p><p>
      TestServiceStub stub = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> TestServiceStub(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">EPR
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p>
      stub._getServiceClient().getOptions().setProperty(
   </p><p>
      Constants.Configuration.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">ENABLE_MTOM
   </font>
        </i>
        <font face="Courier New" size="2">, Constants.</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">VALUE_TRUE
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">set</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">timeout
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(10000);
   </p>
          <p>
          </p>
          <p>
      String base64String = <strike>Base64</strike>.<i>encode</i>(<i>readFully</i>(
   </p>
        </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">INPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">));
   <p></p><p>
      ReceiveMTOM rmtom = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> ReceiveMTOM();
   <p>
      OMFactory fac = OMAbstractFactory.<i>getOMFactory</i>();
   </p><p></p><p>
      OMText binaryNode =fac.createOMText(base64String,
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"application/pdf"</font>
        <font face="Courier New" size="2">,</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   <p>
      OMNamespace omNs = fac.createOMNamespace(
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"http://test.com"</font>
        <font face="Courier New" size="2">, </font>
        <font face="Courier New" color="#2a00ff" size="2">"ns0"</font>
        <font face="Courier New" size="2">);
   <p>
      OMElement method = fac.createOMElement(
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"receiveMTOM"</font>
        <font face="Courier New" size="2">,
   omNs);
   <p>
      method.addChild(binaryNode);
   </p><p>
      rmtom.setElement(method);
   </p><p>
      stub.receiveMTOM(rmtom);
   </p><p></p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"done
   calling service..."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p>
      }
   </p></font>
        <font size="2">
          <p>
      The testMTOM() method creates a stub and sets the enableMTOM property. It then reads
      the a file and then does a base64 encoded on the file's contents. Finally, it calls
      the receiveMTOM() metod on the stub.
   </p>
        </font>
        <font face="Courier New" size="2"> Note that to</font>
        <font size="2"> call
   the web service, we need a sample file. The class above assumes there is a file named
   "small.pdf" at c:\hold\. So create a folder named hold in the root of the c:\ drive
   and copy a pdf file in that directory. Name the file small.pdf.
   <p>
      9. Before you call the service, start TCPMon so we can view the SOAP message that
      the client sends to the service so you can verify that the SOAP Message is really
      an MTOM enabled SOAP request. Configurre TCPMon so that the listen port is 9080 and
      the listener's Target port is 8080. Assuming that Tomcat is running on port 8080.
      Also realize that the client above is setup to call the service on 9080 so as long
      as we configure TCPMon correctly we should be okay. If you are not using TCPMon, change
      the EPR variable in the client class so that it points to port 8080 or whatever port
      your service is running on.
   </p><p>
      10. Assuming you did everything correctly, you should be able to send some MTOM SOAP
      messages to the service. When the service receives a request, it save the binary file
      to c:\hold\att.pdf. 
   </p><p>
       
   </p><b><p>
      References
   </p></b><p>
      1. Download Tomcat: 
   </p></font>
        <a href="http://tomcat.apache.org/download-55.cgi">
          <u>
            <font color="#0000ff" size="2">http://tomcat.apache.org/download-55.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. Download Axis2 version 1.3: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/download/1_3/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/download/1_3/download.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      3. Download TCPMonitor: 
   </p>
        </font>
        <a href="http://ws.apache.org/commons/tcpmon/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/commons/tcpmon/download.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      4. Using TCPMonitor: 
   </p>
        </font>
        <a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html">
          <u>
            <font color="#0000ff" size="2">http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      5. A very good article on MTOM with Axis2: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/1_1_1/mtom-guide.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/1_1_1/mtom-guide.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      6. Apache MTOM User Guide: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/1_0/mtom-guide.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/1_0/mtom-guide.html
   </font>
          </u>
        </a>
        <img width="0" height="0" src="http://www.sayedhashimi.com/aggbug.ashx?id=56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WS-Security, Axis2 and Rampart</title>
    <link rel="alternate" type="text/html" href="http://www.sayedhashimi.com/PermaLink,guid,0511ea6b-35b0-4fce-998c-6cd42a6646ec.aspx" />
    <id>http://www.sayedhashimi.com/PermaLink,guid,0511ea6b-35b0-4fce-998c-6cd42a6646ec.aspx</id>
    <published>2007-10-09T05:00:29.5691250-07:00</published>
    <updated>2007-10-09T05:00:29.5691250-07:00</updated>
    <category term="Web Services" label="Web Services" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <font size="2">
          <p>
      One of the things that I don’t like about Java is that the community is not using
      the same foundational libraries. For example, there is not a standard J2EE application
      server. Instead there is a specification and hundreds of vendors. As a result, everyone
      seems to be using a different implementation of a specification, and thus finding
      answers to questions is a lot harder because the user community is spread across many
      many implementations. 
   </p>
          <p>
      Recently, I had to call a web service which was protected by WS-Security UsernameToken.
      I was able to quickly call the service with Axis 1.1 and WSS4J but when I tried to
      use Axis2 and Rampart I ran into exception after exception. After several days of
      struggling, I was eventually able to create a web service client that created the
      proper soap message. 
   </p>
          <p>
      This blog contains a step by step procedure to create a web service client to a web
      service which is protected by ws-security UsernameToken.
   </p>
          <p>
      I am assuming that you have already deployed the web service which is protected by
      ws-security and that you simply want to call the service using Axis2 version 1.3 and
      Rampart 1.3. Here are the steps:
   </p>
          <p>
      1) Download Axis2 version 1.3 from 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2) Download Rampart 1.3 from 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/modules/index.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/modules/index.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      3) Add Axis2 JARs to your client application classpath--all JARs from the Axis2 distribution
      lib directory.
   </p>
          <p>
      3) Add the Rampart jars to your client application classpath--all jars from the Rampart
      distribution lib directory.
   </p>
          <p>
      4) Create a proxy to the web service that is protected by ws-security--using the WSDL2Java
      tool or batch file.
   </p>
          <p>
      5) Create an Axis2 client-configuration file which engages rampart and which has the
      ws-security parameter. Place this file within your client application project. For
      example, the standard is to create a folder called "conf" for this file.
   </p>
          <p>
      Here is an example file:
   </p>
          <p>
       
   </p>
          <font size="2">
            <p>
      &lt;axisconfig name="AxisJava2.0"&gt;
   </p>
            <p>
      &lt;!-- engage rampart --&gt;
   </p>
            <p>
      &lt;module ref="rampart" /&gt;
   </p>
            <p>
       
   </p>
            <p>
      &lt;!-- ws-security parameters: UsernameToken and PasswordText --&gt; 
   </p>
            <p>
      &lt;parameter name="OutflowSecurity"&gt;
   </p>
            <p>
      &lt;action&gt;
   </p>
            <p>
      &lt;items&gt;UsernameToken&lt;/items&gt;
   </p>
            <p>
      &lt;user&gt;myusername&lt;/user&gt;
   </p>
            <p>
      &lt;passwordCallbackClass&gt;com.mycomp.test.PWCBHandler&lt;/passwordCallbackClass&gt;
   </p>
            <p>
      &lt;passwordType&gt;PasswordText&lt;/passwordType&gt;
   </p>
            <p>
      &lt;/action&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Parameters --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;parameter name="hotdeployment"&gt;true&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="hotupdate"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="enableMTOM"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="enableSwA"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--Uncomment if you want to enable file caching for attachments --&gt;
   </p>
            <p>
      &lt;!--parameter name="cacheAttachments"&gt;true&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="attachmentDIR"&gt;&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="sizeThreshold"&gt;4000&lt;/parameter--&gt;
   </p>
            <p>
      &lt;!--This will give out the timout of the configuration contexts, in seconds--&gt;
   </p>
            <p>
      &lt;parameter name="ConfigContextTimeoutInterval"&gt;30&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--During a fault, stacktrace can be sent with the fault message. The following
      flag will control --&gt;
   </p>
            <p>
      &lt;!--that behaviour.--&gt;
   </p>
            <p>
      &lt;parameter name="sendStacktraceDetailsWithFaults"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="DrillDownToRootCauseForFaultReason"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="userName"&gt;admin&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="password"&gt;axis2&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--Set the flag to true if you want to enable transport level session mangment--&gt;
   </p>
            <p>
      &lt;parameter name="manageTransportSession"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;!-- Following parameter will completely disable REST handling in Axis2--&gt;
   </p>
            <p>
      &lt;parameter name="disableREST" locked="true"&gt;false&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Message Receivers --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!--This is the Deafult Message Receiver for the system , if you want to have MessageReceivers
      for --&gt;
   </p>
            <p>
      &lt;!--all the other MEP implement it and add the correct entry to here , so that
      you can refer from--&gt;
   </p>
            <p>
      &lt;!--any operation --&gt;
   </p>
            <p>
      &lt;!--Note : You can ovride this for particular service by adding the same element
      with your requirement--&gt;
   </p>
            <p>
      &lt;messageReceivers&gt;
   </p>
            <p>
      &lt;messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
   </p>
            <p>
      class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/&gt;
   </p>
            <p>
      &lt;messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
   </p>
            <p>
      class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/&gt;
   </p>
            <p>
      &lt;/messageReceivers&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Message Formatter --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!--Following content type to message formatter mapping can be used to implement
      support for different message --&gt;
   </p>
            <p>
      &lt;!--format serialization in Axis2. These message formats are expected to be resolved
      based on the content type. --&gt;
   </p>
            <p>
      &lt;messageFormatters&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/x-www-form-urlencoded"
   </p>
            <p>
      class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="text/xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/echo+xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;/messageFormatters&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Transport Ins --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;transportReceiver name="http"
   </p>
            <p>
      class="org.apache.axis2.transport.http.SimpleHTTPServer"&gt;
   </p>
            <p>
      &lt;parameter name="port"&gt;6060&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;/transportReceiver&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!--Uncomment this and configure as appropriate for JMS transport support, after
      setting up your JMS environment (e.g. ActiveMQ)
   </p>
            <p>
      &lt;transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"&gt;
   </p>
            <p>
      &lt;parameter name="myTopicConnectionFactory"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;TopicConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="myQueueConnectionFactory"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;QueueConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="default"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;QueueConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;/transportReceiver&gt;--&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Transport Outs --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;transportSender name="tcp"
   </p>
            <p>
      class="org.apache.axis2.transport.tcp.TCPTransportSender"/&gt;
   </p>
            <p>
      &lt;transportSender name="local"
   </p>
            <p>
      class="org.apache.axis2.transport.local.LocalTransportSender"/&gt;
   </p>
            <p>
      &lt;transportSender name="http"
   </p>
            <p>
      class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"&gt;
   </p>
            <p>
      &lt;parameter name="PROTOCOL"&gt;HTTP/1.1&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="Transfer-Encoding"&gt;chunked&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- If following is set to 'true', optional action part of the Content-Type will
      not be added to the SOAP 1.2 messages --&gt;
   </p>
            <p>
      &lt;!-- &lt;parameter name="OmitSOAP12Action"&gt;true&lt;/parameter&gt; --&gt;
   </p>
            <p>
      &lt;/transportSender&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;transportSender name="https"
   </p>
            <p>
      class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"&gt;
   </p>
            <p>
      &lt;parameter name="PROTOCOL"&gt;HTTP/1.1&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="Transfer-Encoding"&gt;chunked&lt;/parameter&gt;
   </p>
            <p>
      &lt;/transportSender&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Global Modules --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Comment this to disable Addressing --&gt;
   </p>
            <p>
      &lt;module ref="addressing"/&gt;
   </p>
            <p>
      &lt;!--Configuring module , providing parameters for modules whether they refer or
      not--&gt;
   </p>
            <p>
      &lt;!--&lt;moduleConfig name="addressing"&gt;--&gt;
   </p>
            <p>
      &lt;!--&lt;parameter name="addressingPara"&gt;N/A&lt;/parameter&gt;--&gt;
   </p>
            <p>
      &lt;!--&lt;/moduleConfig&gt;--&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Clustering --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Configure and uncomment following for preparing Axis2 to a clustered environment
      --&gt;
   </p>
            <p>
      &lt;!-- 
   </p>
            <p>
      &lt;cluster class="org.apache.axis2.cluster.tribes.TribesClusterManager"&gt;
   </p>
            <p>
      &lt;parameter name="param1"&gt;value1&lt;/parameter&gt;
   </p>
            <p>
      &lt;/cluster&gt;
   </p>
            <p>
      --&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Phases --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;phaseOrder type="InFlow"&gt;
   </p>
            <p>
      &lt;!-- System predefined phases --&gt;
   </p>
            <p>
      &lt;phase name="Transport"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Transport"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Transport"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Addressing"&gt;
   </p>
            <p>
      &lt;handler name="AddressingBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Addressing"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;phase name="PreDispatch"/&gt;
   </p>
            <p>
      &lt;phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="RequestURIOperationDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPMessageBodyBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="HTTPLocationBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;!-- System predefined phases --&gt;
   </p>
            <p>
      &lt;!-- After Postdispatch phase module author or service author can add any phase
      he want --&gt;
   </p>
            <p>
      &lt;phase name="OperationInPhase"/&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="OutFlow"&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;phase name="OperationOutPhase"/&gt;
   </p>
            <p>
      &lt;!--system predefined phase--&gt;
   </p>
            <p>
      &lt;!--these phase will run irrespective of the service--&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;phase name="PolicyDetermination"/&gt;
   </p>
            <p>
      &lt;phase name="MessageOut"/&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="InFaultFlow"&gt;
   </p>
            <p>
      &lt;phase name="Addressing"&gt;
   </p>
            <p>
      &lt;handler name="AddressingBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Addressing"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;phase name="PreDispatch"/&gt;
   </p>
            <p>
      &lt;phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="RequestURIOperationDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPMessageBodyBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="HTTPLocationBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="OperationInFaultPhase"/&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="OutFaultFlow"&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;phase name="OperationOutFaultPhase"/&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;phase name="PolicyDetermination"/&gt;
   </p>
            <p>
      &lt;phase name="MessageOut"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;/axisconfig&gt;
   </p>
            <p>
       
   </p>
            <font size="2">
              <p>
      The configuration file above is a typical client config file with the rampart and
      ws-security configuration.
   </p>
              <p>
              </p>
              <p>
      6) When calling the web service through the web service stub, you'll have to give
      Axis the path to the Axis configuration file above. Moreover, for Axis to engage Rampart,
      you'll have to give Axis the path to the Axis respository folder. The repository folder
      needs to have a subdirectory called "modules" and within that directory, the Rampart
      1.3 "mar" file has to exist. Therefore, create a folder somewhere within your project
      called "repository". Then create a subdirectory called "modules". Finally, copy the
      "rampart-1.3.mar" file from the Rampart distributable.
   </p>
              <p>
      7) Now you are ready to make a service call. First create an instance of a custom
      configuration passing in the repository path and the axis configuration file path. 
   </p>
            </font>
            <font face="Courier New" size="2">
              <p>
      ConfigurationContext 
   </p>
            </font>
            <font face="Courier New" size="2">cxt</font>
            <font face="Courier New" size="2"> = 
   <p>
      ConfigurationContextFactory.<i>createConfigurationContextFromFileSystem</i>(
   </p></font>
            <i>
              <font face="Courier New" color="#0000c0" size="2">"c:\\folderpath\\repository"
   </font>
            </i>
          </font>
          <font face="Courier New" size="2">,</font>
          <i>
            <font face="Courier New" color="#0000c0" size="2">"c:\\path_to_axis_config_file.xml"
   </font>
          </i>
        </font>
        <font face="Courier New" size="2">);
   </font>
        <font face="Courier New" size="2">
          <p>
      8) Create a stub with the custom axis configuration instance.
   </p>
        </font>
        <font face="Courier New" size="2">
          <p>
      HelloServiceStub stub = 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> HelloServiceStub(ctx,</font>
        <font face="Courier New" size="2">"http://localhost:8080/services/HelloService"</font>
        <font face="Courier New" size="2">);
   <p></p><p>
      HelloServiceStub.Echo echoReq = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> HelloServiceStub.Echo();
   <p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"calling
   service..."</font>
        <font face="Courier New" size="2">);
   <p></p><p>
      HelloServiceStub.EchoResponse resp = stub.echo(echoReq);
   </p><p></p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"done
   calling service..."</font>
        <font face="Courier New" size="2">);
   </font>
        <i>
          <p>
            <font face="Arial" size="2">The key to the whole process was 
      </font>
          </p>
        </i>ConfigurationContextFactory.<i>createConfigurationContextFromFileSystem. When
   calling this method, you need to make sure you pass the correct repository path and
   a proper Axis2 client configuration file. The path to the repository has to have a
   sub directory called "modules" and that has to contain the rampart "mar" file. If
   this is not correct, then Axis2 will not be able to engage Rampart.
   </i><img width="0" height="0" src="http://www.sayedhashimi.com/aggbug.ashx?id=0511ea6b-35b0-4fce-998c-6cd42a6646ec" /></div>
    </content>
  </entry>
  <entry>
    <title>How to add a start menu icon for your ClickOnce deployed application using MSBuild?</title>
    <link rel="alternate" type="text/html" href="http://www.sayedhashimi.com/PermaLink,guid,69129626-d919-4bf0-b8c0-c1207d4998df.aspx" />
    <id>http://www.sayedhashimi.com/PermaLink,guid,69129626-d919-4bf0-b8c0-c1207d4998df.aspx</id>
    <published>2006-10-11T06:20:56.2656250-07:00</published>
    <updated>2006-10-11T06:20:56.2656250-07:00</updated>
    <category term="ClickOnce" label="ClickOnce" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">If you have an automated
      build and deployment process using MSBuild, then you likely use the <font size="2"><a href="http://http://msdn2.microsoft.com/en-us/library/6wc2ccdc.aspx">GenerateApplicationManifest</a> and <font size="2"><a href="http://msdn2.microsoft.com/en-us/library/3k2t34e7.aspx">GenerateDeploymentManifest</a> tasks
      to create the ClickOnce application and deployment manifest, respectively. If you
      are using these tasks, you may have wondered how you can set an icon (under the
      start menu) for your application. To have an icon set, you have to do several
      things:</font></font></span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">
            </span>
          </font> 
   </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">1) Package the icon
      with the deployment. The easiest way to do this is to add an icon file to your main
      project--that ensure that it gets deployed with the application.</span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">2) After you add
      the icon file, right click on the file in Visual Studio, and set the Build Action
      to Content.</span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">3) At deployment
      time, set the IconFile attribute on GenerateApplicationManifest to the icon file name
      (e.g., myapp.ico), you added in step (1).</span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">
            </span>
          </font> 
   </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">The above will add
      an iconFile attribute to the assembly description element, e.g., &lt;description
      iconFile="myapp.ico" /&gt;, in the application manifest file (e.g., myapp.exe.manifest).
      When ClickOnce sees this attribute set, it will look in the ClickOnce deployment for
      the file and create a Start Menu Icon for your application. </span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">
            </span>
          </font> 
   </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">An interesting thing
      to note is that the iconFile attribute is set in the application manifest and not
      in the deployment manifest. The reason for this is to allow you to change your
      application icons from one deployment to the next.</span>
          </font>
        </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">
            </span>
          </font> 
   </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">
            </span>
          </font> 
   </div>
        <div>
          <font face="Arial" size="2">
            <span class="384295712-11102006">If you are deploying
      your ClickOnce application using Visual Studio and need to set the Start Mneu icon,
      do steps (1) and (2), and then go to the Project | Properties and choose the Application
      tab. Under the Resources group box, set the application icon to the icon you added
      in step (1). ClickOnce should take care of the rest. You can find out more on this
      at <a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=170920&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=170920&amp;SiteID=1"><font title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=170920&amp;SiteID=1" face="Arial"><font title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=170920&amp;SiteID=1" size="2">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=170920&amp;SiteID=1</font></font></a> .</span>
          </font>
        </div>
        <img width="0" height="0" src="http://www.sayedhashimi.com/aggbug.ashx?id=69129626-d919-4bf0-b8c0-c1207d4998df" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Application Block Internals: Demystifying the Object Builder</title>
    <link rel="alternate" type="text/html" href="http://www.sayedhashimi.com/PermaLink,guid,d05aed4f-a211-4969-893e-7ffea324a56c.aspx" />
    <id>http://www.sayedhashimi.com/PermaLink,guid,d05aed4f-a211-4969-893e-7ffea324a56c.aspx</id>
    <published>2006-09-07T10:13:52.4391250-07:00</published>
    <updated>2006-09-07T10:13:52.4391250-07:00</updated>
    <category term="ObjectBuilder" label="ObjectBuilder" scheme="dasBlog" />
    <content type="html">&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;strong&gt;Demystifying
   the ObjectBuilder&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;In
   my last post, I gave an introduction to ObjectBuilder. In this post, I take ObjectBuilder
   apart and talk about all of the hairy details. &lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;ObjectBuilder
   is used in the Enterprise Library, the CAB, and the Mobile framework MS just released.
   If you have to extend any of the above frameworks/libraries in a non-trivial way,
   you are going to need to understand what is going on under the covers. Under the covers
   of the above frameworks/libraries is ObjectBuilder--the dependency injection framework.&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Unfortunately,
   there is not any documentation for the ObjectBuilder, so learning is a real nightmare.
   I was able to break it by going over the unittests that ship with the source code.&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;Fundamental
   Classes in Object Builder&lt;/span&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;i&gt;&lt;u&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;Strategy
   and Policies &lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;- 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   is based upon policies and strategies. Strategies are chained (i.e. 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   implements the Chain of Responsability pattern on strategies) and get registered for
   a build stage.&amp;nbsp; Strategies use policies to figure out how to build an object.
   Policies are registered with 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   for types. A policy is defined for types (objects in 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   are defined by the type and ID). &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;i&gt;&lt;u&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;Locator
   -&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;span style="mso-bidi-font-family: Arial"&gt; locators in 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   are used to find registered objects. When an object is created, it gets registered
   with the locator (see CreationStrategy.RegisterObject).&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;i&gt;&lt;u&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;LifetimeContainer&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;span style="mso-bidi-font-family: Arial"&gt; -
   objects managed by the object builder can have a lifetime associated with them. The
   thing that determines how long an object stays around is the container that the object
   is associated with. LifetimeContainers in 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   , maintain a list of objects. When the container is disposed off, the objects in it
   are also disposed.&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;i&gt;&lt;u&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;BuilderContext- &lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;an
   object that defines the context for the build-up&amp;nbsp;and tear-down of an object.
   BuilderContext holds the strategies, policies and locator for the given build-up or
   tear-down. It also provides a method to iterate the chain of strategies (see IBuilderContext
   and BuilderContext).&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;
   &lt;st1:place w:st="on"&gt;
      &lt;b&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;OB&lt;/span&gt;&lt;/b&gt;
   &lt;/st1:place&gt;
   &lt;b&gt;&lt;span style="mso-bidi-font-family: Arial"&gt; By Example&lt;/span&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;/**********Create
   A Singleton*************/&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;public
   void CreateASingleton()&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // we need a locator, a strategy chain, and a list of policies.&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; Locator locator = new Locator();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; BuilderStrategyChain strategyChain = new BuilderStrategyChain();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; PolicyList policies = new PolicyList();&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // in order to build a singleton, we have to&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // have a SingletonStrategy. The singleton strategy&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // in turn uses a SingletonPolicy.&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // add a SingletonStrategy to the strategy chain&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; strategyChain.Add(new SingletonStrategy());&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // add a CreationStrategy to the strategy chain&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; strategyChain.Add(new CreationStrategy());&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // SingletonStrategy requires a SingletonPolicy&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; policies.Set&amp;lt;ISingletonPolicy&amp;gt;(new SingletonPolicy(true),
   typeof(MyObject), null);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // we also need a creation policy&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; policies.SetDefault&amp;lt;ICreationPolicy&amp;gt;(new DefaultCreationPolicy());&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // in order to make singletons, we need a lifetime container in
   the locator&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; locator.Add(typeof(ILifetimeContainer), new LifetimeContainer());&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // create the object 
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; BuilderContext cxt = new BuilderContext(strategyChain, locator,
   policies);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; // in order to properly track singletons, we have to give the instance
   an ID.&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; object myObj = strategyChain.Head.BuildUp(cxt, typeof(MyObject),
   "MyObject_Singleton", null);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; object myObj2 = strategyChain.Head.BuildUp(cxt, typeof(MyObject),
   "MyObject_Singleton", null);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; if (myObj == myObj2)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Got singleton in myObj2&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int J = 0;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   }&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;The
   example above demonstrates creating singleton objects with the 
   &lt;st1:place w:st="on"&gt;OB.&lt;/st1:place&gt;
   Most of the work simply sets up using the 
   &lt;st1:place w:st="on"&gt;OB.&lt;/st1:place&gt;
   For example, in order to create an object, we need to have a build context. A build
   context requires a locator, a strategy chain, and a policy list. There are several
   pieces that enable singletons, however. For example, utimately a strategy is the thing
   that will create an object in OB. Strategies rely on policies to determine how to
   create an object. To create a singleton, we have to have a SingletonStrategy in the
   strategy chain. The singleton strategy looks for a SingletonPolicy, registered for
   the object being created. Recall that policies are setup for types. &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;There
   are a few design aspects of 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   that we have to understand. 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   uses something called a Locator. A locator knows how to find registered objects. Locators
   can be nested (i.e., a locator can have a parent). Locators make use of something
   called a LifetimeContainer. LifetimeContainer puts a boundary around the lifetime
   of a created object. When a locator is asked to find an object it can look in the
   current locator and/or it's parent locator (if one exists). &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;It's
   important to know that when searching for singletons, 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   looks only at the current locator--the parent is not searched. The SingletonStrategy
   class in 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   is shown below for reinforcement of this.&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;public
   class SingletonStrategy : BuilderStrategy&lt;br&gt;
   &amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; public override object BuildUp(IBuilderContext context, Type typeToBuild,
   object existing, string idToBuild)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   DependencyResolutionLocatorKey key = new DependencyResolutionLocatorKey(typeToBuild,
   idToBuild);&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   if (context.Locator != null &amp;amp;&amp;amp; context.Locator.Contains(key, SearchMode.Local))&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TraceBuildUp(context,
   typeToBuild, idToBuild, "");&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return context.Locator.Get(key);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   return base.BuildUp(context, typeToBuild, existing, idToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp;}&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;As
   shown, the SingletonStrategy checks to see if the build context has a locator,and
   then&amp;nbsp;asks the locator to find the object using a SearchMode.Local. This tells
   the locator not to look in the parent locator for the object. This has obvious usage
   implications--if you don't create your singletons with the correct locator, then you'll
   end up breaking the singleton (TODO: more on this.).&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Also
   note that we have put a CreationStrategy in the chain of strategies for our singleton
   object. The SingletonStrategy ensures that once we have an object, that object is
   returned on subseqent build-up requests. The CreationStrategy is needed to build-up
   the object the first time. Since the CreationStrategy is the strategy that builds
   the object, this strategy also registers the object with the locator/container so
   that it can be pulled out the next time. We can see this by looking at the CreationStrategy.&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;public
   class CreationStrategy : BuilderStrategy&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;public override object BuildUp(IBuilderContext context, Type typeToBuild,
   object existing, string idToBuild)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;if (existing != null)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BuildUpExistingObject(context, typeToBuild, existing, idToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;existing = BuildUpNewObject(context, typeToBuild, existing,
   idToBuild);&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return
   base.BuildUp(context, typeToBuild, existing, idToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;private
   void BuildUpExistingObject(IBuilderContext context, Type typeToBuild, object existing,
   string idToBuild)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;RegisterObject(context, typeToBuild, existing, idToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;[SecurityPermission(SecurityAction.Demand,
   Flags = SecurityPermissionFlag.SerializationFormatter)]&lt;br&gt;
   &amp;nbsp;&amp;nbsp;private object BuildUpNewObject(IBuilderContext context, Type typeToBuild,
   object existing, string idToBuild)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;ICreationPolicy policy = context.Policies.Get&amp;lt;ICreationPolicy&amp;gt;(typeToBuild,
   idToBuild);&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if
   (policy == null)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (idToBuild == null)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.Resources.MissingPolicyUnnamed, typeToBuild));&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.Resources.MissingPolicyNamed, typeToBuild,
   idToBuild));&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;existing = FormatterServices.GetSafeUninitializedObject(typeToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;catch (MemberAccessException exception)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
   Properties.Resources.CannotCreateInstanceOfType, typeToBuild), exception);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;RegisterObject(context,
   typeToBuild, existing, idToBuild);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;InitializeObject(context, existing, idToBuild, policy);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;return existing;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;private
   void RegisterObject(IBuilderContext context, Type typeToBuild, object existing, string
   idToBuild)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;if (context.Locator != null)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ILifetimeContainer lifetime = context.Locator.Get&amp;lt;ILifetimeContainer&amp;gt;(typeof(ILifetimeContainer),
   SearchMode.Local);&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if
   (lifetime != null)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ISingletonPolicy singletonPolicy = context.Policies.Get&amp;lt;ISingletonPolicy&amp;gt;(typeToBuild,
   idToBuild);&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if
   (singletonPolicy != null &amp;amp;&amp;amp; singletonPolicy.IsSingleton)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;context.Locator.Add(new DependencyResolutionLocatorKey(typeToBuild,
   idToBuild), existing);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lifetime.Add(existing);&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if
   (TraceEnabled(context))&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TraceBuildUp(context, typeToBuild, idToBuild,
   Properties.Resources.SingletonRegistered);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;}&lt;br&gt;
   &amp;nbsp;&amp;nbsp;//...more methods ....&lt;br&gt;
   }&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;As
   shown above, the BuildUp method checks to see if it has to build-up a new object or
   an existing one. In our case, we are building up an object for the firsttime. In this
   case, the BuildUpNewObject method is called. This method looks on the build context
   for a ICreationPolicy for the required object. If it doesn't find one, it throws an
   exception--in other words, you have to have a policy registered for the object that
   tells 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   how to create the object. In our case, we are using the DefaultCreationPolicy. If
   there is a ICreationPolicy, then the method builds a bare-bones object (one that is
   not initialized) using&amp;nbsp; &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;&lt;font color=#000000&gt;existing
   = &lt;/font&gt;&lt;span style="COLOR: teal"&gt;FormatterServices&lt;/span&gt;&lt;font color=#000000&gt;.GetSafeUninitializedObject(typeToBuild);&lt;/font&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;and
   then calls RegisterObject(). This is where the singleton magic happens. As you can
   see from the code snippet above, the CreationStrategy looks for a lifetime container
   on the local locator and if one exists, it looks for a singleton policy registered
   for the required object. If it finds the singleton policy, it adds a key for the newly
   build object to the lifetime container. &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;Thus,
   we can conclude that in order to create singleton objects with 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   , we need to have a SingletonStrategy and a SingletonPolicy. There are two aspects
   to creating a singleton: &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;ol type=1&gt;
   &lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
      &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;When
      creating an object, you have to register it. &lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
      &lt;o:p&gt;&lt;/o:p&gt;
      &lt;/span&gt;&lt;/font&gt;&lt;/font&gt; 
   &lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
      &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;When
      creating an object, you have to check to see if one already exists.&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
      &lt;o:p&gt;&lt;/o:p&gt;
      &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
   &lt;/li&gt;
&lt;/ol&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;The
   singleton policy, ensures that the object gets registered with the local locator's
   lifetime container and the singleton strategy ensures that the registered object gets
   returned on subsequent build-up operations.&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;
   &lt;st1:place w:st="on"&gt;
      &lt;span style="mso-bidi-font-family: Arial"&gt;OB&lt;/span&gt;
   &lt;/st1:place&gt;
   &lt;span style="mso-bidi-font-family: Arial"&gt; is a glorified object factory and DI framework.
   To support DI, 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   ships with some strategies and policies. Lets investigate these now. [TODO: Correct
   this intro into DI via Properties]&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;Injecting
   into&amp;nbsp;Properties&lt;/span&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;DI
   in 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   is achived at build-up. When you ask OB to build-up an object, 
   &lt;st1:place w:st="on"&gt;OB&lt;/st1:place&gt;
   runs a chain of strategies. The idea is to inject dependencies into objects at build-up.
   To do that, you put a strategy object, an object&amp;nbsp;that knows how to do the proper
   injection, into the chain of strategies.&amp;nbsp;One of the strategies that knows how
   to inject dependencies is the PropertySetterStrategy. An example will help.&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;
   &lt;o:p&gt;&lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
   &lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;public
   void PropertyInjectionExample()&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp;Locator locator = new Locator();&lt;br&gt;
   &amp;nbsp;LifetimeContainer container = new LifetimeContainer();&lt;br&gt;
   &amp;nbsp;locator.Add(typeof(ILifetimeContainer), container);&lt;br&gt;
   &amp;nbsp;// strategies ...&lt;br&gt;
   &amp;nbsp;BuilderStrategyChain chain = new BuilderStrategyChain();&lt;br&gt;
   &amp;nbsp;chain.Add(new CreationStrategy());&lt;br&gt;
   &amp;nbsp;chain.Add(new PropertySetterStrategy());&lt;br&gt;
   &amp;nbsp;// policies...&lt;br&gt;
   &amp;nbsp;PolicyList policies = new PolicyList();&lt;br&gt;
   &amp;nbsp;// Property setter policy for MyDAOObject's ConnectionString&lt;br&gt;
   &amp;nbsp;PropertySetterPolicy psp = new PropertySetterPolicy();&lt;br&gt;
   &amp;nbsp;// add a property for the ConnectionString property 
   &lt;br&gt;
   &amp;nbsp;psp.Properties.Add("ConnectionString", new PropertySetterInfo("ConnectionString",new
   ValueParameter&amp;lt;string&amp;gt;("the connection s