<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Abstract form</title>
	<atom:link href="http://abstractform.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://abstractform.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 15 Dec 2009 15:20:59 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='abstractform.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/5adce80c353c9342357e696958e19ebd?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Abstract form</title>
		<link>http://abstractform.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://abstractform.wordpress.com/osd.xml" title="Abstract form" />
		<item>
		<title>Higher spatial dimensions</title>
		<link>http://abstractform.wordpress.com/2009/12/15/higher-spatial-dimensions/</link>
		<comments>http://abstractform.wordpress.com/2009/12/15/higher-spatial-dimensions/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 15:14:18 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[flatland]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[universe]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=182</guid>
		<description><![CDATA[A few days ago I had an interesting discussions about the existence of other dimensions. In my experience most people who have heard about Big Bang, relativity or even inflationary theory are unfamiliar with have a vague understating of this concept. Although higher spatial dimensions are extremely easy to understand and even have applications in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=182&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A few days ago I had an interesting discussions about the existence of other dimensions. In my experience most people who have heard about Big Bang, relativity or even inflationary theory are unfamiliar with have a vague understating of this concept. Although higher spatial dimensions are extremely easy to understand and even have applications in everyday circumstances.</p>
<p>Most of us are familiar with the idea of flatlanders (thanks to <a href="http://www.youtube.com/watch?v=UnURElCzGc0">Carl Sagan</a>), 2-dimensional flat creatures that live on a plane, or a surface. A flatlander can never see a 3rd dimension but he can deal with it mathematically. A flatlander can certainly understand points, lines, circles and all other 2D geometrical objects. A flatlander needs 2 piece of information to identify any point in his universe: X and Y. He should have no problem in imagining line-lander creatures who need one piece of information to identify the positions in their universe: X. He can think that his flatland is made of infinite number of line-lands. To make a flatland you have to take a line-land and drag it in a direction orthogonal to it.</p>
<p>Flatlander knows that any position in line-land can be described by:</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7BLine%7D+%3D+%28X%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{Line} = (X)' title='Position_{Line} = (X)' class='latex' /></p>
<p>And any position in flatland can be described by:</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7BFlat%7D+%3D++%28X+%2C+Y%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{Flat} =  (X , Y)' title='Position_{Flat} =  (X , Y)' class='latex' /></p>
<p>Or</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7BFlat%7D+%3D+Position_%7BLine%7D+%2C+Y&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{Flat} = Position_{Line} , Y' title='Position_{Flat} = Position_{Line} , Y' class='latex' /></p>
<p>Y is a dimension that is unknown to line-landers and is the direction that we dragged the line-land to create a flatland.</p>
<p>We as 3-dimensional creatures can think that our 3D world is made of a flatland, dragged in a direction orthogonal to it. Any position in our world can be described by:</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7BVolume%7D+%3D+%28X%2C+Y%2C+Z%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{Volume} = (X, Y, Z)' title='Position_{Volume} = (X, Y, Z)' class='latex' /></p>
<p>Or</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7BVolume%7D+%3D+Position_%7BFlat%7D%2C+Z&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{Volume} = Position_{Flat}, Z' title='Position_{Volume} = Position_{Flat}, Z' class='latex' /></p>
<p>Z is the new direction that is orthogonal to flatland.</p>
<p>You already got the picture, a 4-dimensional creature can drag our volume-land in a direction orthogonal to it to create his 4D world and so on.</p>
<p><img src='http://l.wordpress.com/latex.php?latex=Position_%7B4D%7D+%3D+Position_%7BVolume%7D%2C+W&#038;bg=fff&#038;fg=222&#038;s=0' alt='Position_{4D} = Position_{Volume}, W' title='Position_{4D} = Position_{Volume}, W' class='latex' /> (W is the new dimension).</p>
<p>In other words:<br />
A line-lander has no idea of a flatland. The position is only X for him. He describes a 0-land by X.<br />
A flatlander describes a line-land by <img src='http://l.wordpress.com/latex.php?latex=Y+%3D+%28X%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='Y = (X)' title='Y = (X)' class='latex' />, a set of <img src='http://l.wordpress.com/latex.php?latex=X&#038;bg=fff&#038;fg=222&#038;s=0' alt='X' title='X' class='latex' />s.<br />
A volume-lander describes a flatland by <img src='http://l.wordpress.com/latex.php?latex=Z+%3D+%28X%2C+Y%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='Z = (X, Y)' title='Z = (X, Y)' class='latex' />, a set of <img src='http://l.wordpress.com/latex.php?latex=%28X%2C+Y%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='(X, Y)' title='(X, Y)' class='latex' />s<br />
A 4D-lander describes a volume-land by <img src='http://l.wordpress.com/latex.php?latex=W+%3D+%28X%2C+Y%2C+Z%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='W = (X, Y, Z)' title='W = (X, Y, Z)' class='latex' />, a set of <img src='http://l.wordpress.com/latex.php?latex=%28X%2C+Y%2C+Z%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='(X, Y, Z)' title='(X, Y, Z)' class='latex' />s.</p>
<p>From elementary mathematics you must remember that a set of objects could be described by a function. For example if <img src='http://l.wordpress.com/latex.php?latex=F&#038;bg=fff&#038;fg=222&#038;s=0' alt='F' title='F' class='latex' /> is a function defined on real numbers and for each real number that it receives it returns another real number then:<br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+F%28x%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = F(x)' title='y = F(x)' class='latex' /><br />
Is the description of a line-land from a flatlander&#8217;s point of view.<br />
Other kinds of line-lands include:<br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+x&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = x' title='y = x' class='latex' /><br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+4+x+%2B+5.12&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = 4 x + 5.12' title='y = 4 x + 5.12' class='latex' /><br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+x%5E2&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = x^2' title='y = x^2' class='latex' /><br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+%5Csin%28x%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = \sin(x)' title='y = \sin(x)' class='latex' /><br />
<img src='http://l.wordpress.com/latex.php?latex=y+%3D+2%28%5Csin%28x%29+%2B+%5Ccos%28x%29%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='y = 2(\sin(x) + \cos(x))' title='y = 2(\sin(x) + \cos(x))' class='latex' /><br />
And so on.</p>
<p>The line-lander only knows about X. If somebody tells him that his line-land is a part of a flat-land he doesn’t immediately find out what F function describes his line-land the flatland. But F is easily known to the flatlanders who are studying the line-land. Generally F describes the shape of the universe in a higher spatial dimension.</p>
<p>Let&#8217;s talk about an interesting example. Assume that the line-land world as it is seen by our flatlanders is a circle. It means that <img src='http://l.wordpress.com/latex.php?latex=F+%3D+%5Cpm+%5Csqrt%7Br%5E2-x%5E2-y%5E2%7D+&#038;bg=fff&#038;fg=222&#038;s=0' alt='F = \pm \sqrt{r^2-x^2-y^2} ' title='F = \pm \sqrt{r^2-x^2-y^2} ' class='latex' />. The poor line-lander has no idea about the 2-dimensional shape of his world but he can find it out.</p>
<p>The line-lander finds out that his world is indeed bounded if he starts walking toward a direction and reaches the starting point.</p>
<p>A sphere is a 3-dimensional circle, F for a sphere is:<br />
<img src='http://l.wordpress.com/latex.php?latex=F+%3D+%5Cpm+%5Csqrt%7Br%5E2-x%5E2-y%5E2-z%5E2%7D+&#038;bg=fff&#038;fg=222&#038;s=0' alt='F = \pm \sqrt{r^2-x^2-y^2-z^2} ' title='F = \pm \sqrt{r^2-x^2-y^2-z^2} ' class='latex' /></p>
<p>Let&#8217;s rewrite these two equations in a more usual form:</p>
<p>1D Circle: <img src='http://l.wordpress.com/latex.php?latex=x%5E2%2By%5E2+-+a%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='x^2+y^2 - a^2 = 0' title='x^2+y^2 - a^2 = 0' class='latex' /><br />
2D Sphere: <img src='http://l.wordpress.com/latex.php?latex=x%5E2+%2B+y%5E2+%2B+z%5E2+-+a%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='x^2 + y^2 + z^2 - a^2 = 0' title='x^2 + y^2 + z^2 - a^2 = 0' class='latex' /></p>
<p>Look at the pattern:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="64" valign="top">0D</td>
<td width="112" valign="top">A   Pair of Points</td>
<td width="238" valign="top"><img src='http://l.wordpress.com/latex.php?latex=x%5E2+++-+a%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='x^2   - a^2 = 0' title='x^2   - a^2 = 0' class='latex' /></td>
<td width="288" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Comega_1+%3A%3D+%5Cleft+%28x%5E2+-+a%5E2+%5Cright+%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='\omega_1 := \left (x^2 - a^2 \right )' title='\omega_1 := \left (x^2 - a^2 \right )' class='latex' /></td>
</tr>
<tr>
<td width="64" valign="top">1D</td>
<td width="112" valign="top">Circle</td>
<td width="238" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%28x%5E2+-+a%5E2%29+%2B+y%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='(x^2 - a^2) + y^2 = 0' title='(x^2 - a^2) + y^2 = 0' class='latex' /></td>
<td width="288" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Comega_1+%2B+y%5E2+%3D+0%2C+%5C%3A+%5C%3A+%5Comega_2+%3A%3D++%5Cleft+%5B+%5Comega_1+%2B+y%5E2+%5Cright+%5D&#038;bg=fff&#038;fg=222&#038;s=0' alt='\omega_1 + y^2 = 0, \: \: \omega_2 :=  \left [ \omega_1 + y^2 \right ]' title='\omega_1 + y^2 = 0, \: \: \omega_2 :=  \left [ \omega_1 + y^2 \right ]' class='latex' /></td>
</tr>
<tr>
<td width="64" valign="top">2D</td>
<td width="112" valign="top">Sphere</td>
<td width="238" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Cleft+%5B%28x%5E2+-+a%5E2%29+%2B+y%5E2+%5Cright+%5D+%2B+z%5E2%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='\left [(x^2 - a^2) + y^2 \right ] + z^2= 0' title='\left [(x^2 - a^2) + y^2 \right ] + z^2= 0' class='latex' /></td>
<td width="288" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Comega_2+%2B+z%5E2+%3D+0%2C+%5C%3A+%5C%3A+%5Comega_3+%3A%3D+%5Cleft+%5C%7B+%5Cleft+%5B+%5Cleft+%28+x%5E2-a%5E2+%5Cright+%29+%2B+y%5E2+%5Cright+%5D+%2B+z%5E2+%5Cright+%5C%7D&#038;bg=fff&#038;fg=222&#038;s=0' alt='\omega_2 + z^2 = 0, \: \: \omega_3 := \left \{ \left [ \left ( x^2-a^2 \right ) + y^2 \right ] + z^2 \right \}' title='\omega_2 + z^2 = 0, \: \: \omega_3 := \left \{ \left [ \left ( x^2-a^2 \right ) + y^2 \right ] + z^2 \right \}' class='latex' /></td>
</tr>
<tr>
<td width="64" valign="top">3D</td>
<td width="112" valign="top">3-Sphere</td>
<td width="238" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Cleft+%5C%7B+%5Cleft+%5B%28x%5E2+-+a%5E2%29+%2B+y%5E2+%5Cright+%5D+%2B+z%5E2+%5Cright+%5C%7D+%2B+w%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='\left \{ \left [(x^2 - a^2) + y^2 \right ] + z^2 \right \} + w^2 = 0' title='\left \{ \left [(x^2 - a^2) + y^2 \right ] + z^2 \right \} + w^2 = 0' class='latex' /></td>
<td width="288" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Comega_3+%2B+w%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='\omega_3 + w^2 = 0' title='\omega_3 + w^2 = 0' class='latex' /></td>
</tr>
<tr>
<td width="64" valign="top">ND</td>
<td width="112" valign="top">N-Sphere</td>
<td width="238" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Csum+%7BX_%7Bn%5E2%7D%7D+-+a%5E2%2C+%5C%3A+%5C%3A+n+%3D+0+%5C%3A+to+%5C%3A+N&#038;bg=fff&#038;fg=222&#038;s=0' alt='\sum {X_{n^2}} - a^2, \: \: n = 0 \: to \: N' title='\sum {X_{n^2}} - a^2, \: \: n = 0 \: to \: N' class='latex' /></td>
<td width="288" valign="top"><img src='http://l.wordpress.com/latex.php?latex=%5Comega_%7BN-1%7D+%2B+X_N%5E2+%3D+0&#038;bg=fff&#038;fg=222&#038;s=0' alt='\omega_{N-1} + X_N^2 = 0' title='\omega_{N-1} + X_N^2 = 0' class='latex' /></td>
</tr>
</tbody>
</table>
<p>The surface of a sphere could be described by many circles. The smallest circle at the north pole is a point, the radius of the circles grows as we reach the equator and then again shrinks back to 0 at south pole. This is best described in this form of spherical coordinates:</p>
<p><img src='http://l.wordpress.com/latex.php?latex=x_1+%3Da%5Ccos%28%5Cphi_1%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='x_1 =a\cos(\phi_1)' title='x_1 =a\cos(\phi_1)' class='latex' /> is a circle. A sphere is a collection of circles stacked on each other. The circles at north and south pole have 0 radius and the radius of the circle at equator is maximum (a). We can think that the radius of these circles change by: <img src='http://l.wordpress.com/latex.php?latex=r+%3D+a%5Ccos%28%5Cphi_2%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='r = a\cos(\phi_2)' title='r = a\cos(\phi_2)' class='latex' />. This <img src='http://l.wordpress.com/latex.php?latex=%5Cphi_2&#038;bg=fff&#038;fg=222&#038;s=0' alt='\phi_2' title='\phi_2' class='latex' /> is orthogonal to <img src='http://l.wordpress.com/latex.php?latex=%5Cphi_1&#038;bg=fff&#038;fg=222&#038;s=0' alt='\phi_1' title='\phi_1' class='latex' /> (and is in the new dimension).</p>
<p>So <img src='http://l.wordpress.com/latex.php?latex=x_2+%3Da%5Ccos%28%5Cphi_2%29%5Csin%28%5Cphi_1%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='x_2 =a\cos(\phi_2)\sin(\phi_1)' title='x_2 =a\cos(\phi_2)\sin(\phi_1)' class='latex' /> describes a sphere.</p>
<p>In the same sense you can think that a circle is made of many pairs of points. At the top of the circle the distance between the pairs is 0, it reaches a maximum in equator and again 0 in the bottom.</p>
<p>Now we can extend this model to higher dimension spheres. Take a 3D sphere with radius 0, increase the radius to a maximum and then shrink it back to 0; you have a 3-sphere.</p>
<p><img src='http://l.wordpress.com/latex.php?latex=x_3+%3D+a%5Ccos%28%5Cphi_3%29sin%28%5Cphi_2%29%5Csin%28%5Cphi_1%29&#038;bg=fff&#038;fg=222&#038;s=0' alt='x_3 = a\cos(\phi_3)sin(\phi_2)\sin(\phi_1)' title='x_3 = a\cos(\phi_3)sin(\phi_2)\sin(\phi_1)' class='latex' /> is a 3-sphere (a 4 dimensional sphere)</p>
<p>This way you can make other higher dimensional shapes. Note that here we only talked about spatial dimensions.<br />
For example a stack of lines in Y-direction makes a square, a stack of flat squares in Z direction makes a cube and a stack of cubes in W direction makes a tesseract.</p>
<p>Take a look at the projection of a tesseract (4D cube) in 3D space <a href="http://www.youtube.com/watch?v=5xN4DxdiFrs">here</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=182&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/12/15/higher-spatial-dimensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Hollywood Principle</title>
		<link>http://abstractform.wordpress.com/2009/12/07/hollywood-principle/</link>
		<comments>http://abstractform.wordpress.com/2009/12/07/hollywood-principle/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:57:53 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=175</guid>
		<description><![CDATA[Today I was working on refactoring some names in Hyzobox In/Out API. It is my personal favorite piece of code in the whole platform. In summary it allows the publisher of the game to customize the game in runtime dynamically by injecting codes and executing some functions in the context of the game (In) and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=175&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today I was working on refactoring some names in Hyzobox In/Out API. It is my personal favorite piece of code in the whole <a href="http://www.hyzonia.com">platform</a>. In summary it allows the publisher of the game to customize the game in runtime dynamically by injecting codes and executing some functions in the context of the game (In) and to get notified about the events that are occurring inside the game (Out).</p>
<p>Inversion of Control is very natural in JavaScript and it has been used extensively in In/Out API. It&#8217;s quite different from popular prototype pattern but most everyday JavaScript programmers use IoC even though they don&#8217;t usually notice it.</p>
<p>Here is a sample in our API:</p>
<p>We register an event listener in Hyzobox, waiting for landing view of the game to be loaded:</p>
<pre>
var hb = Hyzobox.createInstance();
var landingview_loaded = function(hbEvent) {
   // do something with hbEvent
}
hb.addEventListener('landingview_loaded', landingview_loaded);
</pre>
<p>It&#8217;s is clear that we don&#8217;t have control over when landingview_loaded event will be fired and its handler will be called.</p>
<p>hbEvent argument that is of type Hyzobox.Event has a data attribute that is of type Object. In this example the data is a LandingView instance. We can interact with this object in the event handler:</p>
<pre>
var landingview_loaded = function(hbEvent) {
   var view = hbEvent.data;
   view.inject('a-container-id', 'some text');
};
</pre>
<p>In this example we are injecting &#8217;some text&#8217; to an element identified by &#8216;a-container-id&#8217; inside landing view.</p>
<p>addEventListener() is part of Out and inject() is part of In API. If we want to listen to the events that are occurring inside a particular view, we should register their halnders after the view has been loaded:</p>
<pre>
var landingview_loaded = function(hbEvent) {
   var view = hbEvent.data;
   view.attachEventListener('playNow', function playNowHandler(playNowHbEvent) {
       // do something with playNowHbEvent
   });
};
</pre>
<p>And so on, we can have many nested Ins and Outs.</p>
<p>It&#8217;s easy to see that in these examples the control has been transferred to the event handlers. The caller raise the events but it&#8217;s the responsibility of the handlers to control the functionalities.</p>
<p>I don&#8217;t want to go into the the details now, because the work hasn&#8217;t yet been finished on these APIs. Once released, we will post them in <a href="http://docs.hyzonia.com">Hyzobox documentations</a> and <a href="http://tech.hyzonia.com">Hyzonia tech blog</a> in the following weeks.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=175&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/12/07/hollywood-principle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Microfinancing, Lending vs donating</title>
		<link>http://abstractform.wordpress.com/2009/11/29/lending-vs-donating/</link>
		<comments>http://abstractform.wordpress.com/2009/11/29/lending-vs-donating/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 19:49:29 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[Politics]]></category>
		<category><![CDATA[atheism]]></category>
		<category><![CDATA[microfinancing]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=166</guid>
		<description><![CDATA[I want to talk about what the brilliant idea microfinancing is.
I grew up in an Islamic family &#8211; however in my childhood they were not as conservative as they are now. It&#8217;s a tradition in Iran and I think it is also an Islamic rule to donate some portion of your surplus to poor people; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=166&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I want to talk about what the brilliant idea microfinancing is.</p>
<p>I grew up in an Islamic family &#8211; however in my childhood they were not as conservative as they are now. It&#8217;s a tradition in Iran and I think it is also an Islamic rule to donate some portion of your surplus to poor people; usually the people you know from your work, or in the neighborhood. Currently in Iran there is a well systematic Islamic donation process, and I think people are obliged to donate one fifth of their yearly surplus to this system. And no matter where you are, we are all used to see charities everywhere and in different occasions (like thanks giving or new year). Just a disclaimer that I&#8217;m by far not an expert in this area, but I&#8217;ve always believed charities are not a solution to poverty, they make it worse, they distribute poverty. They keep poor people poor. If the poor person is jobless, donations don&#8217;t help him in getting hired, and if the poor person is receiving a very low wage, the charity doesn&#8217;t urge the employer to pay more.</p>
<p>During the past months there were times that I was finding myself dangerously inclined toward social ideas and then I was swinging back to &#8216;prosperity&#8217; and capitalism. But this issue that you have to always start form some place bigger than zero to have a life in a capitalistic society had been bothering me. Now I think microfinancing is a reasonable solution for this problem.</p>
<p>Why do you want to donate to somebody and loose some money? Why don&#8217;t you lend him the money so he can start a business and pay you back? I understand that charities might be vital for some regions of the world, but I&#8217;m sure most of the donations that my family is doing in Iran will not be used in those regions.</p>
<p>&#8216;Carlos needs $1,100 to buy some pigs&#8217; he will return the loan in a year, but no bank is lending him, simply because the cost of processing the loan is higher than the profit. But this website: <a href="http://www.kiva.org">www.kiva.org</a> is making it possible for Carlos to raise the money in a matter of a week. Carlos will not be another homeless beggar, he is starting his own business and his future depends on how hard he works and how well he manages the business. He will not need charity and in a few months he should be able to even hire employees and extend his business.</p>
<p>I was impressed that my like-minded people are among the <a href="http://www.kiva.org/app.php?page=community&amp;kv_orderBy=amt_loaned&amp;kv_direction=DESC&amp;kv_page=1">top lenders</a> of Kiva. Yeah! I think superstitious people have a hard time digesting this idea that they, not God, can help people to stand on their own two feet and overcome poverty. And of course the LGBT community that are helping their entrepreneurs to achieve their own equality.<br />
That’s pretty all I wanted to say, I have something beautiful to think about tonight.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=166&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/11/29/lending-vs-donating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Truth vs. Hollywood</title>
		<link>http://abstractform.wordpress.com/2009/11/15/truth-vs-hollywood/</link>
		<comments>http://abstractform.wordpress.com/2009/11/15/truth-vs-hollywood/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:49:51 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=162</guid>
		<description><![CDATA[I was reading this interesting column in NY Times, Mistakes in Typography by Alice Rawsthorn. Honestly it&#8217;s the first time I ever looked at typography from this point of view. I can feel her view about typographical errors, usually I feel similar when I see a scientifically incorrect assertion in a movie for example.
Sometimes I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=162&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was reading this interesting column in NY Times, <a href="http://www.nytimes.com/2009/11/16/arts/16iht-design16.html?_r=1&amp;hp">Mistakes in Typography</a> by Alice Rawsthorn. Honestly it&#8217;s the first time I ever looked at typography from this point of view. I can feel her view about typographical errors, usually I feel similar when I see a scientifically incorrect assertion in a movie for example.</p>
<p>Sometimes I think movies are not textbooks, they just should not be too wrong. But changing the truth to make it more cinematic has been OK with me. If we want Hollywood appreciate scientific values, we have to realize its rules too.</p>
<p>For now, I&#8217;m just enjoying reading this article.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=162&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/11/15/truth-vs-hollywood/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Unfollow people who are not following you</title>
		<link>http://abstractform.wordpress.com/2009/11/01/unfollow-people-who-are-not-following-you/</link>
		<comments>http://abstractform.wordpress.com/2009/11/01/unfollow-people-who-are-not-following-you/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 20:59:40 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[unfollow]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=160</guid>
		<description><![CDATA[Last week I learnt that one well known way to increase the number of followers in Twitter is to follow as many people as you can. Chances are that finally a ratio of them (in our experiment something around one third) will follow you back.
The problem is that you cannot hide the truth, anybody who [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=160&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Last week I learnt that one well known way to increase the number of followers in Twitter is to follow as many people as you can. Chances are that finally a ratio of them (in our experiment something around one third) will follow you back.</p>
<p>The problem is that you cannot hide the truth, anybody who visits your Twitter page, will see the number of following is much bigger than the followers.</p>
<p>SocialOOMPH has a tool that automatically <a href="http://www.socialoomph.com/"> unfollows people who unfollow you</a>. Assuming that some of our followers are using this tool, we should not unfollow our followers. But it seems to be perfectly safe to unfollow people who are not following you.</p>
<p>I spent an hour or so in the weekend to take a look at Twitter API and write a small program that does this job. I quite amazed by the simplicity of Twitter API, now I wonder why aren&#8217;t we in our company spending time to study it in more details. It&#8217;s interesting that it seems the guys in Twitter have had similar naming problems to ours. For example in the API terminology the people who you are following, are your &#8216;friends&#8217;.</p>
<p>My program is a simple C# Console application and you need .NET Framework 3.5 to run it. Download <a href="http://www.wingooli.com/fs/code/FriendsCleanUp.zip">Unfollow people who are not following me program here</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=160&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/11/01/unfollow-people-who-are-not-following-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Two in morning and&#8230;</title>
		<link>http://abstractform.wordpress.com/2009/10/25/two-in-morning-and/</link>
		<comments>http://abstractform.wordpress.com/2009/10/25/two-in-morning-and/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 22:14:39 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Company]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[advergaming]]></category>
		<category><![CDATA[atheism]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[science]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=158</guid>
		<description><![CDATA[It&#8217;s two in morning and I can&#8217;t sleep.
Today we moved part of Hyzonia, essentially its Core and global services to a new server. Finally. It&#8217;s a Windows 2008, and I quite surprised how smooth this transition was, so far.
I&#8217;m trying to stimulate! the moods in the company. I&#8217;m trying to be more passionate, talk and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=158&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It&#8217;s two in morning and I can&#8217;t sleep.<br />
Today we moved part of Hyzonia, essentially its Core and global services to a new server. Finally. It&#8217;s a Windows 2008, and I quite surprised how smooth this transition was, so far.</p>
<p>I&#8217;m trying to stimulate! the moods in the company. I&#8217;m trying to be more passionate, talk and make people talk more. The goal is to make most of everybody&#8217;s intelligence. Everyone should feel she has an effect on business decisions. I don&#8217;t need man power, I need mind power. It requires quite a force to shake this high inertia, change opposing company. I&#8217;m relaxing many rules, and I&#8217;m handing over many decision making tasks to my team. We gotta be a team that play together with our minds not our muscles. I&#8217;m already seeing some results and I expect to observe a measurable improvement  in a matter of few weeks. We are starting new exciting projects, some of them are just show-offs (read it releases) and some are absolutely new crazy wild ideas.</p>
<p>Sometime I feel I&#8217;ve lost much of my passions, but I&#8217;m trying hard to prove it&#8217;s a wrong, evil feeling. Most of all <a href="http://www.youtube.com/watch?v=PxjfZG_szRg">Richard Dawkins</a> is helping me to remember I supposed to be more a scientist than a boring business man.</p>
<p>My team is energized since we got somebody in NetAd to work with our game customization API. Back in two week ago I was arguing that the whole customization API was a waste of time, I was thinking nobody will use it and eventually it would be our job to customize the games. I&#8217;m happy (indeed) that I was wrong. And you know there&#8217;s nothing more funnier, more relaxing than being happy because you were wrong.</p>
<p>Anyway, we launched <a href="http://www.hyzogames.com">HyzoGames</a> that contains some samples of the customized games. We&#8217;re trying to keep <a href="http://twitter.com/hyzonia">Hyzonia Twitter</a> account active. So if you care, follow us there. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>No, I can&#8217;t take it anymore, &#8216;night!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=158&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/10/25/two-in-morning-and/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing Remote ASP.NET Web Services using JSONP</title>
		<link>http://abstractform.wordpress.com/2009/10/12/accessing-remote-asp-net-web-services-using-jsonp/</link>
		<comments>http://abstractform.wordpress.com/2009/10/12/accessing-remote-asp-net-web-services-using-jsonp/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 15:32:47 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Cross Site Scripting]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JSONP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[xhr]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=146</guid>
		<description><![CDATA[The problem:
You cannot call remote ASP.NET web service methods from a JavaScript, AJAX client.
Example:
You have a web service, at this address: http://a.com/service.asmx and you&#8217;ve configured the service to work with AJAX clients:
[WebService
(Namespace = "http://www.hyzonia.com/gametypes/PopNDropLikeGame/WS2")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class GameService : System.Web.Services.WebService
{
    [WebMethod(EnableSession = true)]
    public GameSessionResponse CreateGameSession(Guid questId)
    [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=146&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>The problem:</h2>
<p>You cannot call remote ASP.NET web service methods from a JavaScript, AJAX client.</p>
<h3>Example:</h3>
<p>You have a web service, at this address: <a href="http://a.com/service.asmx">http://a.com/service.asmx</a> and you&#8217;ve configured the service to work with AJAX clients:</p>
<pre>[WebService
(Namespace = "http://www.hyzonia.com/gametypes/PopNDropLikeGame/WS2")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class GameService : System.Web.Services.WebService
{
    [WebMethod(EnableSession = true)]
    public GameSessionResponse CreateGameSession(Guid questId)
    {
...
    }
}
}</pre>
<p>And it works fine when you call its methods from a web page that is in this address: <a href="http://a.com/page.htm">http://a.com/page.htm</a>:</p>
<pre>$.ajax({
        type: "POST",
        url: "GameService.asmx/CreateGameSession",
        data: "{questId: '" + questId + "'}",
        cache: false,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            Game._onSessionGot(response.d);
        }
    });</pre>
<p>But the very same client-side code doesn’t work from this address: <a href="http://b.clom/page.htm">http://b.clom/page.htm</a></p>
<h3>The problem in depth:</h3>
<p>At first I cannot hold myself and not say that it is a silly problem. web services are meant to be called by remote clients. The fact that browsers block access to web services by AJAX calls is clearly contrary to the purpose of web services.</p>
<p>Interestingly browser extensions like Flash and Silverlight also by default block remote web services, but they provide a work around. Unfortunately no browser by date supports this work around for XMLHTTPRequests. This &#8220;security measure&#8221; seems odder when we notice that it is perfectly correct to import a JavaScript code snippet from another domain by a script tag:</p>
<pre>&lt;script
src="<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js</a>"
type="text/javascript"&gt;&lt;/script&gt;
</pre>
<p>&nbsp;</p>
<h2>
The solution:</h2>
<p>As it was said, Flash and Silverlight both support remote calls. You just need a <a href="http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx">clientaccesspolicy</a> file to be hosted at the root of a.com (<a href="http://a.com/clientaccesspolicy.xml">http://a.com/clientaccesspolicy.xml</a>):</p>
<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;access-policy&gt;
  &lt;cross-domain-access&gt;
    &lt;policy&gt;
      &lt;allow-from http-request-headers="SOAPAction"&gt;
        &lt;domain uri="*"/&gt;
      &lt;/allow-from&gt;
      &lt;grant-to&gt;
        &lt;resource path="/" include-subpaths="true"/&gt;
      &lt;/grant-to&gt;
    &lt;/policy&gt;
  &lt;/cross-domain-access&gt;
&lt;/access-policy&gt;</pre>
<p>This file allows remote calls to be made from any other domain.</p>
<p>But in many situations we want to call the web service methods directly by AJAX clients. This need was the cause of to the development of <a href="http://www.ibm.com/developerworks/library/wa-aj-jsonp1/">JSONP (JSON with padding) protocol</a>. As it was discussed it is correct to have a &lt;script&gt; element that loads a script from another domain. On the other hand you may know that it is possible to load scripts dynamically by a simple JavaScript trick (writing&lt;script&gt; tags) or using <a href="http://plugins.jquery.com/project/include">this jQuery plug in</a>. Now the bulbs are flickering! The solution is to access the JSON web service by the src attribute of a &lt;script&gt; element. This is the whole idea behind JSONP.</p>
<p>But there are a couple of problems needed to be solved for ASP.NET ASMX web services before we can use them in a JSONP scenario.</p>
<ol>
<li>ASP.NET web services by default only accept POST requests, a &lt;script src=&#8221;"&gt; element, produces a GET request.</li>
<li>The result of the web method call must conform to JSONP, and you guess, ASP.NET 3.5 by default doesn’t support it.</li>
</ol>
<p>The solution to the first problem may seem trivial, we can easily enable GET calls to web methods using [ScriptMethod(UseHttpGet = true)] attribute. The immediate problem is that when we mark a web method by this attribute it only can be called by GET requests. And remember, other clients (actually anything other than JSONP clients) are supposed to communicate with the web service by POST requests. I usually end up inheriting from the original web service and marking web methods by [ScriptMethod(UseHttpGet = true)] attribute in the derived class. Therefore I will have two ASMX web services, one using the original class (expecting POST request) and the other using the derived class (expecting GET requests).</p>
<pre>[WebMethod(), ScriptMethod(UseHttpGet = true)]
public override GameSessionResponse CreateGameSession(Guid questId)
{
   return base.CreateGameSession(questId);
}</pre>
<p>Note you may need to add this code snippet in web.config:</p>
<pre>&lt;system.web&gt;
 &lt;webServices&gt;
   &lt;protocols&gt;
     &lt;add name="HttpGet"/&gt;
   &lt;/protocols&gt;
 &lt;/webServices&gt;
…
&lt;/system.web&gt;</pre>
<p>There&#8217;s another problem to be addressed in the client side. The client should call the web method by a correct URL (it has to pass a correct query string that could be deserialized back to .NET objects in the server side). In case of POST requests, I&#8217;m used to JSON2 library to post data to ASP.NET ASMX web services. Jquery $.AJAX method (when it is configured to use JSONP, by dataType: &#8220;jsonp&#8221;) creates query string parameters for the data object it receives. But the result is not usable for ASMX web services.</p>
<p>Luckily there&#8217;s a ready to use JQuery plug in (<a href="http://plugins.jquery.com/project/jMsAjax">jMsAjax</a>) that has the required algorithms for serializing a JavaScript object into a query string that can be parsed by ASP.NET web services.</p>
<p>Using the plug in I created this function to serialize JavaScript objects into query strings:</p>
<pre>$.jmsajaxurl = function(options) {
    var url = options.url;
    url += "/" + options.method;
    if (options.data) {
       var data = ""; for (var i in options.data) {
       if (data != "")
         data += "&amp;"; data += i + "=" + msJSON.stringify(options.data[i]);
       }
       url += "?" + data; data = null; options.data = "{}";
   }
<pre style="font:normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">   return url;
};</pre>
</pre>
<p>You will need jMsAjax for this code snippet to work.</p>
<p>Finally this is a sample of a client side code using JQuery that calls an ASMX web service using JSONP:</p>
<pre>var url = $.jmsajaxurl({
    url: "http://hiddenobjects.hyzonia.com/services/GameService3.asmx",
    method: "Login",
    data: { email: "myemail@mydomain.com", password: "mypassword" }
});

$.ajax({
    cache: false,
    dataType: "jsonp",
    success: function(d) { console.log(d); },
    url: url + "&amp;format=json"
});</pre>
<p>Or equivalently:</p>
<pre>$.getJSON(url + "&amp;callback=?&amp;format=json", function(data) {
    console.log(data);
});</pre>
<p>When you call an ASP.NET web service method (that is configured to receive GET requests) using a code similar to the above, it returns in XML. The problem is that the web service expects to receive a request that has a content type of &#8220;application/json; charset=utf-8&#8243; and &lt;script&gt; element simply doesn&#8217;t add this content type to the request. There&#8217;s a little thing we can do at the client side. The easiest way to resolve this problem is to use a HTTP module. The HTTP module should add this content type to the requests before they are processed by the web service handler.</p>
<p>On the other hand a JSONP client expects that the web service return the call by a string like this:</p>
<pre>nameOfACallBackFunction(JSON_OBJECT_WEB_METHOD_RETURNED)</pre>
<p><code>nameOfACallBackFunction</code> must be given to the server by a parameter in the query string. Different JSONP compatible web services use different names for this parameter, but usually it is named &#8216;callback&#8217;. At least this is what $.ajax() automatically adds to the request in JSONP mode.</p>
<p>I grabbed this HTTP module from <a href="http://elegantcode.com/2008/12/02/calling-remote-aspnet-web-services-from-jquery/">a post in elegantcode.com</a>.</p>
<pre>public class JsonHttpModule : IHttpModule
{
    private const string JSON_CONTENT_TYPE = "application/json; charset=utf-8";

    #region IHttpModule Members
    public void Dispose()
    {
    }

    public void Init(HttpApplication app)
    {
        app.BeginRequest += OnBeginRequest;
        app.ReleaseRequestState += OnReleaseRequestState;
    }
    #endregion

    bool _Apply(HttpRequest request)
    {
        if (!request.Url.AbsolutePath.Contains(".asmx")) return false;
        if ("json" != request.QueryString.Get("format")) return false;
        return true;
    }

    public void OnBeginRequest(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;

        if (!_Apply(app.Context.Request)) return;

        if (string.IsNullOrEmpty(app.Context.Request.ContentType))
        {
            app.Context.Request.ContentType = JSON_CONTENT_TYPE;
        }
    }

    public void OnReleaseRequestState(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;

        if (!_Apply(app.Context.Request)) return;

        app.Context.Response.Filter = new JsonResponseFilter(app.Context.Response.Filter, app.Context);
    }
}

public class JsonResponseFilter : Stream
{
    private readonly Stream _responseStream;
    private HttpContext _context;

    public JsonResponseFilter(Stream responseStream, HttpContext context)
    {
        _responseStream = responseStream;
        _context = context;
    }

    public override bool CanRead { get { return true; } }

    public override bool CanSeek { get { return true; } }

    public override bool CanWrite { get { return true; } }

    public override long Length { get { return 0; } }

    public override long Position { get; set; }

    public override void Write(byte[] buffer, int offset, int count)
    {
        var b1 = Encoding.UTF8.GetBytes(_context.Request.Params["callback"] + "(");
        _responseStream.Write(b1, 0, b1.Length);
        _responseStream.Write(buffer, offset, count);
        var b2 = Encoding.UTF8.GetBytes(");");
        _responseStream.Write(b2, 0, b2.Length);
    }

    public override void Close()
    {
        _responseStream.Close();
    }

    public override void Flush()
    {
        _responseStream.Flush();
    }

    public override long Seek(long offset, SeekOrigin origin)
    {
        return _responseStream.Seek(offset, origin);
    }

    public override void SetLength(long length)
    {
        _responseStream.SetLength(length);
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return _responseStream.Read(buffer, offset, count);
    }
}</pre>
<p>This HTTP module will be applied to each request to a .asmx file that has a <code>format=json</code> in its query string.</p>
<p>Note that you have to update web.config:</p>
<pre>&lt;system.web&gt;
…
  &lt;httpModules&gt;
    …
    &lt;add name="JSONAsmx"/&gt;
  &lt;/httpModules&gt;
&lt;/system.web&gt;</pre>
<p>For IIS6 and</p>
<pre>&lt;system.webServer&gt;
  &lt;modules&gt;
  …
    &lt;add name="JSONAsmx"/&gt;
  &lt;/modules&gt;
  …
&lt;/system.webServer&gt;</pre>
<p>For IIS7.</p>
<p>Now to test is open your web service in your browser, in my example:</p>
<p><a href="http://hiddenobjects.hyzonia.com/services/GameService3.asmx/Login?email=e@e.com&amp;password=p">http://hiddenobjects.hyzonia.com/services/GameService3.asmx/Login?email=e@e.com&amp;password=p</a></p>
<p>It should return in XML</p>
<p>And</p>
<p><a href="http://hiddenobjects.hyzonia.com/services/GameService3.asmx/Login?email=%22e@e.com%22&amp;password=%22p%22&amp;format=json&amp;callback=myCallBackFunc">http://hiddenobjects.hyzonia.com/services/GameService3.asmx/Login?email=&#8221;e@e.com&#8221;&amp;password=&#8221;p&#8221;&amp;format=json&amp;callback=myCallBackFunc</a></p>
<p>Will return:</p>
<pre>myCallBackFunc({"d":{"__type":"HLoginResponse",
"isSuccessful":false,"error":false,"authSessionId":null,"nickName":null,"score":0}});</pre>
<p>Don&#8217;t worry about myCallBackFunc, JQuery nicely manages it, so that the whole business is behind the scene and you can use $.ajax success callback the very same way you use it for a normal AJAX call.</p>
<p>We should note that JSONP has its own problems, especially… yes&#8230; in IE! All versions of Internet Explorer has a <a href="http://support.microsoft.com/kb/208427">2083 character limit</a> for the URL of a request. It means that you cannot send large data in GET requests to the server. Sometime this limitation leaves us with no choice but to use Flash or create a proxy to the remote web service in the local domain.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=146&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/10/12/accessing-remote-asp-net-web-services-using-jsonp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Why make an advergame for Hyzonia?</title>
		<link>http://abstractform.wordpress.com/2009/08/14/why-make-an-advergame-for-hyzonia/</link>
		<comments>http://abstractform.wordpress.com/2009/08/14/why-make-an-advergame-for-hyzonia/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 21:50:13 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[advergame]]></category>
		<category><![CDATA[advergaming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[online advertising]]></category>
		<category><![CDATA[service oriented architecture]]></category>
		<category><![CDATA[soa]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=138</guid>
		<description><![CDATA[We have been working on a few cool features of Hyzonia in the past weeks. Hyzonia is a next generation internet ad service. Like traditional ad services Hyzonia receives advertisements from advertisers and distribute them in websites. But the ad materials in Hyzonia are not in the form of traditional banner or text ads. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=138&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>We have been working on a few cool features of <a href="http://www.hyzonia.com">Hyzonia </a>in the past weeks. Hyzonia is a next generation internet ad service. Like traditional ad services Hyzonia receives advertisements from advertisers and distribute them in websites. But the ad materials in Hyzonia are not in the form of traditional banner or text ads. The ads would be placed inside games, in a way that players would interact and engage with the promoted subjects. This kind of games is being called an advergame. I don&#8217;t want to dig into the marketing stuff, but it worths mentioning that one interesting feature of Hyzonia is that it makes it easier for advertisers to utilize the power of advergaming, for less, as Hyzonia is providing a rich set of ready-to-use advergames. Using Hyzonia customers do not need to pay big moneys to interactive software companies to make and host an advergame as part of their online campaign.</p>
<p>We already have built a number of  favorite games, but Hyzonia is extensible by nature, meaning that it is easy to create an advergame for Hyzonia or integrate an already built game into it. Like almost every big web business we know, we found it is crucial for Hyzonia to be extensible and customizable. Hence we spent the last few weeks on making final touches on the first version of our APIs, improving security and testing it all by making sample games.</p>
<p>It&#8217;s no myth that most succesful indie developers are game makers. If you have some good ideas, you may find your two-week project shining on the top lists in Xbox Live or Apple Store.</p>
<p>In comparison with those programs, in Hyzonia you will start earning from the moment your game is added in the system. It would be based on a revenue sharing model, so as long as your game is attractive for promoters there would be some campaigns active in some instances of your game and a revenue stream for you. On the other hand contrary to Miniclip or Pogo, Hyzonia is not a single game portal, your game eventually will be displayed in our publishers&#8217; websites. Hyzonia is a service that provides the infrastructure needed for this communication among advertisers, publishers, and developers to happen.</p>
<p>Currently in addition of standard Web Service interfaces we are providing .NET libraries that encapsulate all the basic functionalities that an advergame in Hyzonia platform should support. One exciting news is that you don&#8217;t need to make everything from scratch using Hyzonia APIs, but the required functionalities of an advergame in Hyzonia have been designed in a way to make it possible to take virtually any game, wrap it inside a shell (we call Island) and have it added in Hyzonia. The .NET libraries that we are shipping as part of the API have all the functionalities needed by this shell.</p>
<p>Because of its service oriented architecture, Hyzonia advergames (Islands) could be anywhere in the internet. But currently we are only activating the games that have been hosted physically in our datacenters, although exactly like a banner ad (hosted let&#8217;s say by DoubleClick) they could be displayed on other websites.</p>
<p>Obviously not any game can be converted into an advergame. This is another issue that we are adderssing it in the guidelines that will be released alongside the APIs.</p>
<p><img class="aligncenter" title="Connecting advertisers, game developers and website owners" src="http://www.gliffy.com/pubdoc/1793238/M.jpg" alt="" width="409" height="420" /> A thousand words: Hyzonia connects developers, advertisers and websites.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=138&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/08/14/why-make-an-advergame-for-hyzonia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>

		<media:content url="http://www.gliffy.com/pubdoc/1793238/M.jpg" medium="image">
			<media:title type="html">Connecting advertisers, game developers and website owners</media:title>
		</media:content>
	</item>
		<item>
		<title>Returning Anonymous Types in Web Services</title>
		<link>http://abstractform.wordpress.com/2009/07/09/returning-anonymous-types-in-web-services/</link>
		<comments>http://abstractform.wordpress.com/2009/07/09/returning-anonymous-types-in-web-services/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 17:02:55 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/?p=132</guid>
		<description><![CDATA[When coding an AJAX app that makes relatively many calls to the server in short periods of time, the main concern is to minimize the bandwidth it consumes. For example think of an AJAX chat application. For it to look like a real time app we have to query the server every few seconds.
If you&#8217;re using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=132&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When coding an AJAX app that makes relatively many calls to the server in short periods of time, the main concern is to minimize the bandwidth it consumes. For example think of an AJAX chat application. For it to look like a real time app we have to query the server every few seconds.</p>
<p>If you&#8217;re using .NET, you already knew how easy it is to return objects and have them serialized in JSON in Web Services. All we need to do is to deal with the logics and .NET does all the things and tricks related to the communication. For our example, this is the method that needed to be called periodically from the client:</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">[<span style="color:#2b91af;">WebMethod</span>]</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;"><span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">ChatMessage</span>&gt; GetMessages()</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">{</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">var</span> currentPlayer = OnlinePlayers.Single(p =&gt; p.Id == CurrentPlayerId);</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">var</span> messages = Messages.Where(m =&gt; m.DateSent &gt; currentPlayer.DateSynced);</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;">currentPlayer.DateSynced = <span style="color:#2b91af;">DateTime</span>.Now;</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">return</span> messages;</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">}</p>
<p>The problem is that .NET really serializes everything. If we have the following definitions:</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">[<span style="color:#2b91af;">Serializable</span>]</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Player</span></p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">{</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> Player() { }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> Name { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> Id { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> PhotoUrl { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:#2b91af;">DateTime</span> DateSynced { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;color:green;margin:0 0 0 .375in;">// other properties</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">}</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">
<p style="font-family:Calibri;font-size:11pt;margin:0;">[<span style="color:#2b91af;">Serializable</span>]</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChatMessage</span></p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">{</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> ChatMessage() { }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:#2b91af;">Player</span> Sender { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> Message { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:#2b91af;">DateTime</span> DateSent { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</p>
<p style="font-family:Calibri;font-size:11pt;margin:0;">}</p>
<p>It is certainly not desirable to send a Player object back to the client by every ChatMessage. Assuming that the client already knows all the Players involved in the Chat, the ChatMessage object that is being sent to the client only needs to have a Sender ID property. One obvious solution that is very familiar for hardcore client-server developers is to have another type, let&#8217;s say ClientChatMessage that only contains the required information. If you&#8217;re taking this approach remember ClientChatMessage should be a struct type:</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">[<span style="color:#2b91af;">WebMethod</span>]</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;"><span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">ClientChatMessage</span>&gt; GetMessages()</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">{</p>
<p style="font-family:Consolas;font-size:9.5pt;color:green;margin:0 0 0 .375in;">//&#8230;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">return</span> messages.Select(m =&gt; (<span style="color:#2b91af;">ClientChatMessage</span>)m);</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">}</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">[<span style="color:#2b91af;">Serializable</span>]</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">struct</span> <span style="color:#2b91af;">ClientChatMessage</span></p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">{</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> SenderId;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:#2b91af;">DateTime</span> DateSent;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> Message;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;">
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">explicit</span> <span style="color:blue;">operator</span> <span style="color:#2b91af;">ClientChatMessage</span>(<span style="color:#2b91af;">ChatMessage</span> m)</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;">{</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;"><span style="color:blue;">return</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">ClientChatMessage</span>()</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;">{</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 1.125in;">DateSent = m.DateSent,</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 1.125in;">Message = m.Message,</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 1.125in;">SenderId = m.Sender.Id</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;">};</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;">}</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">}</p>
<p>When we are targeting only AJAX clients it&#8217;s very handy to return anonymously typed objects. Anonymous objects cannot be serialized by XML serialization, but JavaScript (JSON) serializer is able to serialize them. I prefer it:</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">[<span style="color:#2b91af;">WebMethod</span>]</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;"><span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">Object</span>&gt; GetMessages()</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">{</p>
<p style="font-family:Consolas;font-size:9.5pt;color:green;margin:0 0 0 .375in;">//&#8230;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">return</span> messages.Select(m =&gt;</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;"><span style="color:blue;">new</span> {</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;">s = m.Sender.Id,</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;">m = m.Message,</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .75in;">d = m.DateSent</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0 0 0 .375in;">});</p>
<p style="font-family:Consolas;font-size:9.5pt;margin:0;">}</p>
<p>Here I&#8217;ve shortened the names of the properties, hey it is AJAX, we should save bandwidth by every mean possible.</p>
<p>We&#8217;ve used this trick in many places of the games we are developing for <a href="http://www.hyzonia.com">Hyzonia</a>, as the current games only will be available for JavaScript clients. We found another similar trick very handy: a web method can take an object as an argument; if you send a JSON serialized object from the client to these methods, you&#8217;ll have a Dictionary&lt;String, Object&gt; in the server side.</p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">[WebMethod]</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">public IEnumerable&lt;ChatMessage&gt; GetMessages()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">var currentPlayer = OnlinePlayers.Single(p =&gt; p.Id == CurrentPlayerId);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">var messages = Messages.Where(m =&gt; m.DateSent &gt; currentPlayer.DateSynced);</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">currentPlayer.DateSynced = DateTime.Now;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">return messages;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:37px;width:1px;height:1px;">}</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=132&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/07/09/returning-anonymous-types-in-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
		<item>
		<title>Lecture in UOWD</title>
		<link>http://abstractform.wordpress.com/2009/07/04/lecture-in-uowd/</link>
		<comments>http://abstractform.wordpress.com/2009/07/04/lecture-in-uowd/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 13:57:14 +0000</pubDate>
		<dc:creator>Homam Hosseini</dc:creator>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[Dubai]]></category>
		<category><![CDATA[advergaming]]></category>
		<category><![CDATA[hyzonia]]></category>
		<category><![CDATA[lecture]]></category>
		<category><![CDATA[rena]]></category>
		<category><![CDATA[uowd]]></category>

		<guid isPermaLink="false">http://abstractform.wordpress.com/2009/07/04/lecture-in-uowd/</guid>
		<description><![CDATA[Reza, our business dev manager, has a lecture on advergaming in UOWD. Everybody&#8217;s welcome to join: http://blog.hyzonia.com
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=130&subd=abstractform&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Reza, our business dev manager, has a lecture on advergaming in UOWD. Everybody&#8217;s welcome to join: <a href="http://blog.hyzonia.com">http://blog.hyzonia.com</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abstractform.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abstractform.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abstractform.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abstractform.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abstractform.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abstractform.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abstractform.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abstractform.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abstractform.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abstractform.wordpress.com/130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abstractform.wordpress.com&blog=5674805&post=130&subd=abstractform&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://abstractform.wordpress.com/2009/07/04/lecture-in-uowd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Homam</media:title>
		</media:content>
	</item>
	</channel>
</rss>