Archive
Poem: The Horizon
This one i wrote on July 2nd, 2009.
The standard disclaimers apply, the poem was originally written in Hebrew therefore the translation may lose or change some of the meanings, rhyming, wordplay, etc.
~ The Horizon ~
I found myself sitting before the horizon
Looking at that distant line
The border between a memory and a touch
A divider between my past and the dream.
I found myself for one moment content
for an instant gazing at it aloof
It – that cuts the imagination to broken shards of glass
The ever threatening wave that is reluctant to come.
As I sat there, I found a tree nearby
Old it was, barren limbs, leafs no longer growing
like me its gaze is full of wonder
but the tree is staying here and I’m already disappearing.
I found myself thinking about that disconcerting horizon
Does more life exist beyond its colors?
Is it covering an internal light, or rather,
Is it holding back the darkness from blanketing my world?
Does the horizon also have searching eyes?
Does it see my already fading footsteps?
For a moment it pleased me to sit here
but I’m rising to go, I’m already disappearing.
The original Hebrew version:
~ האופק ~
מצאתי עצמי יושב מול האופק
מביט אל אותו קו מרוחק
הגבול בין זכרון ובין נגיעה
חוצץ שעובר בין עברי והחלום.
מצאתי עצמי לרגע מרוצה
לרגע באדישות לעברו בוהה
הוא שחותך דמיון לזכוכית שבורה
הגל המאיים אך שלא מגיע.
בעודי יושב שם מצאתי לידי עץ
עץ זקן, ענפיו ריקים ועליו לא צומחים
כמוני הוא מסתכל לעבר האופק ומשתהה
אך הוא נשאר כאן ואני כבר נעלם.
מצאתי עצמי חושב על אותו אופק מתעתע
האם מעבר לצבעיו יישנם עוד חיים?
האם הוא מסתיר אור נצחי, או שמא,
מחזיק מבעד החושך לכסות עולמי?
האם גם לאופק עיניים מחפשות?
האם רואה את עקבותיי שכבר מטשטשות?
לרגע קט הישיבה נעמה לי
אך אני קם והולך, אני כבר נעלם.
Favorite Poems of the Day Up to Date: 21/08/2009
As some of you know I’ve taken upon myself to try and publish a link to a poem i like per day on Twitter: #PoemOfTheDay.
Admittedly, I havent been able to keep it up everyday since I started but I did manage to share quite a few over the past few months.
I’d like to take the opportunity to collect some of my personal recent favorites in this post.
Enjoy!
August 19th 2009 – “Metallic Wing” by Efrat Mishori: http://tinyurl.com/mdlv57 – “Metallic wing in its socket, beating unseen.”
August 18th 2009 – “Pleasure for Pleasure” by Peter Stavropoulos: http://bit.ly/3Y7S4O – “…Pleasure for pleasure will surely start”
August 13th 2009 – “Night Heron” by Samuel Peralta: http://bit.ly/rtZ1m – “rising from the waters / like a dream.”
August 11th 2009 – “Sonnet 56” by William Shakespeare: http://bit.ly/hPEcw – “Sweet love, renew thy force! Be it not said…”
August 10th 2009 – “from: Prayers of Atonement” by Lea Goldberg http://bit.ly/klx4t -”If there were torments–then they voyaged toward you”
August 3rd 2009 – “Endless Poem” by Yehuda Amichai: http://bit.ly/jGQ7o – “Within me / My heart / Within my heart / A museum”
July 30th 2009 – “Listening” by Amy Lowell: http://bit.ly/1K8pK – “‘T is you that are the music, not your song…”
July 27th 2009 – “The Garden” by Mark Strand: http://bit.ly/rSKuf – “it shines: even now in the moment before it disappears.”
July 26th 2009 – “Song of Hope” by Thomas Hardy: http://bit.ly/n4rlU – “To-morrow shines soon -Shines soon!”
July 21st 2009 – “On Pain” by Khalil Gibran: http://bit.ly/vmHgr – “…your pain would not seem less wondrous than your joy…”
July 17th 2009 - “Petals” by Amy Lowell: http://twurl.nl/s5v6ai – “…Petal by petal the flower of our heart…”
July 16th 2009 – “When the Eyes Open” by Dahlia Ravikovitz: http://bit.ly/Z8Re0 -”as the soul returns to the body when the eyes open.”
July 15th 2009 – “Touched by an Angel” by Maya Angelou: http://bit.ly/uAerx – “Yet it is only love which sets us free.”
July 12th 2009 – “A Pearl, a Girl” by Robert Browning: http://bit.ly/6rDpB -”…Through the love in a girl!”
July 10th 2009 – “Valentine” by Carol Ann Duffy: http://bit.ly/YMoIj -”I give you an onion. It is a moon wrapped in brown paper…”
July 4th 2009 – “Moonwalk” by Samuel Peralta : http://bit.ly/4sbHqx -”…The words begin to form a song / The melody begins to burn…”
July 3rd 2009 – “Wild Nights” by Emily Dickinson: http://bit.ly/qOMhk -”…Wild nights should be Our luxury!…”
July 1st 2009 – “If You Forget Me” by Pablo Neruda: http://bit.ly/1j9EgT -”if each day,each hour,you feel that you are destined for..”
Poem: Distant Thoughts
This one i wrote in June 2004:
The standard disclaimers apply, the poem was originally written in Hebrew therefore the translation may lose or change some of the meanings, rhyming, wordplay, etc.
~ Distant Thoughts ~
Lost,
Cannot find her
She won’t come back to me
No gentle word will be enough.
Drowning,
Air is no longer found
The will to breathe gone as well
My life is where she is
And she is gone.
Blind,
No light is strong enough
No scream in the dark is heard
It is just the wind blowing in the gaping hole
She was mine but no more.
Stumbling,
Step after step
Direction unknown
She will not be there when I arrive
Where will that be – doesn’t matter.
Dreaming,
The Images a blur
Like leafs a moment before the storm
What was – that was no dream
As real as pain
Pain of loss and longing
The dream slowly dissipates
Not Breaking,
Not whole either
A piece is distant and missing
Even when the wound heals
The scar will remain to remind me
And she, she will also be with me.
The original Hebrew version:
~ מחשבות רחוקות ~
אבדתי,
אינני מוצא אותה
שוב אלי היא לא תחזור
שום מילה עדינה לא תספיק.
טובע,
האוויר גם הוא לא בנמצא
והרצון לנשום גם הוא נעלם
חיי היכן שהיא תהיה
והיא איננה.
עיוור,
אף אור לא חזק מספיק
אף צעקה בחושך איננה נשמעת
רק הרוח המנשבת בחלל שנפער
שלי הייתה אך לא עוד.
מועד,
צעד אחר צעד
הכיוון אינו ידוע
אך היא לא תהיה שם כשאגיע
גם לא תהיה שם לפני שאלך
לאן – זה כבר לא משנה.
חולם,
התמונות מסתחררות
כמו העלים רגע לפני שהסערה מגיעה
אך מה שהיה לא חלום הוא
אמיתי כמו הכאב
כאב של אובדן וגעגוע
אט אט מתפוגג לו החלום.
לא נשבר,
אך גם לא שלם באמת
משהו חסר ותמיד רחוק
גם שהפצע יחלים
הצלקת תשאר להזכיר לי
והיא, גם היא תשאר איתי.
Creating a Webservice Proxy with jQuery
Contents
Introduction
In a previous post I’ve shown how to use WCF, jQuery and jTemplates to retrieve information from the server and lay it out on the page using jTemplates’ templating engine.
The code example in that article used the Microsoft Ajax client library and the proxy it creates at run time to ease the javascript code needed to call the methods of the webservice I created.
In this article I would like to show you an easy way of creating a similar proxy to the Microsoft one in pure javascript and the help of jQuery’s AJAX capabilities. This makes a lot of sense if you do not have the option to use the MS library on the client or simply because you don’t want to.
I will be relying mostly on the code examples and concepts I described in the previous article so I’d recommend reading it first before continuing to read this one.
You can let me know if you find this article useful or not by using the ratings and comments below.
Server Side
The good news: no need to change anything on the server side, the web service can continue to work as it always did. All we’re doing in this exercise is to replace the client side logic and so we will not touch the server code.
Client Side
Using the same website I’ve shown how to create in the previous article we will create the new proxy for our WCF webservice.
In the System folder create a javascript file and call it ServiceProxy.js, To the file add the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
ServiceProxy = function() //constructor for the proxy
{
this._baseURL = "Services/TutorialService.svc/";
};
ServiceProxy.prototype =
{
_defaultErrorHandler: function(xhr, status, error)
{
alert(xhr.statusText);
},
_doAjax: function(method, data, fnSuccess, fnError)
{
if (!data) data = {};
if (!fnError) fnError = this._defaultErrorHandler;
$.ajax({
type: "GET",
url: this._baseURL + method,
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: fnSuccess,
error: fnError,
dataFilter: function(data)
{
var response;
if (typeof (JSON) !== "undefined" && typeof (JSON.parse) === "function")
response = JSON.parse(data);
else
response = val("(" + data + ")");
if (response.hasOwnProperty("d"))
return response.d;
else
return response;
}
});
}
};
|
Lets examine the code:
The first section is the constructor of the proxy object, in there we define the base URL of the service we will be calling.
The second method is _defaultErrorHandler, this is a default error handler, its strictly a developer friendly method, allowing the calling method to leave the pointer to an error handling method empty. Of course the implementation of this default error handler should be changed in a real life scenario as its not wise to show any raw error information to a website’s visitor.
The third and most important method is _doAjax, this is where the “magic” happens which takes care of the back and forward communication with the server.
The first two lines take care of the defaults, if there is no data passed to the webservice we assign an empty object and if there is no pointer supplied to an error handler we assign our default method.
Next is the where we use jQuery’s incredibly convenient Ajax method, lets examine this call, jQuery’s ajax method accepts an object that sets all the needed information:
‘type’: The HTTP verb: could be GET, POST, etc. In this example we use GET since we’re only retrieving from the server.
For a more robust scenario we would probably want to turn this into a parameter of the method.
‘url’: The URL of the webservice method, in this case the base URL defined in the constructor and the name of the method.
‘data’: The parameters passed to the service method, constructed as a JSON object.
‘contentType’: the content type of the data being sent to the server. In our case we’re communicating with the webservice using JSON and therefore we use: “application/json; charset=utf-8”
‘success’: A pointer to the method to be called when the asynchronous call has finished successfully.
‘error’: A pointer to the method to be called when the asynchronous call finished with an error.
‘dataFilter’: I’ve taken the code block in this example from Dave Ward’s Encosia blog. I will add the links to a couple of his articles at the end of this post.
The dataFilter is used whenever there is a successful response from the server and allows us to modify the response in any way we like before its passed to the success method.
In this example there are two uses to the filter: The first one is to turn the response into a JSON object from the string result coming from the server. It will first check whether the current browser supports JSON parsing natively (Firefox 3.5, IE8 for example). If it does it will use the native JSON object and if not will use the less optimized and less secure eval() function.
The second part is to check whether the response is enclosed within a ‘d’ property, this ‘d’ property is added automatically by Microsoft’s WCF service and since we want to abstract this fact from the caller we only return the relevant response if this is the case.
Now that we have everything we need for our base proxy functionality all we need to do is add the methods that match the exposed methods on the webservice. To the prototype of the ServiceProxy object add these two methods:
1 2 3 4 5 6 7 8 9 10 11 |
getArticles: function(success, error)
{
this._doAjax("GetArticles", null, success, error);
},
getArticle: function(link, success, error)
{
var data = {link: link};
this._doAjax("GetArticle", data, success, error)
},
|
These two methods call our _doAjax, passing the necessary information such as the method name and the parameters if needed to the call.
In fact the methods mirror the methods available on the webservice thus completing the proxy.
Now the only thing to do is create a HTML file (or any other file, could even be JSP) that will replace the aspx page we created in the previous article.
You can find all the source code in the example site ive made available for download, in this post I will only show the changes needed.
- First, create a default.html in the root of the site.
- In the head element add these links:
<script src=”System/jquery.js” type=”text/javascript”></script>
<script src=”System/jquery-jtemplates.js” type=”text/javascript”></script>
<script src=”System/ServiceProxy.js” type=”text/javascript”></script>
<link href=”System/Styles.css” rel=”stylesheet” type=”text/css” />
- Copy over the entire javascript element.
- Add the following code as the first line of the script to declare the proxy:
<script type="text/javascript">
var proxy = new ServiceProxy();
- In the document ready function replace the call to the GetArticles method with this one:
1 2 3 4 |
$(document).ready(function() //executes this code when page loading is done
{
proxy.getArticles(articlesRetrieved);
});
|
- In the loadArticle function replace the call to getArticle with this one:
1 2 3 4 5 6 7 |
function loadArticle(link)
{
$("#LoadingImg").removeClass("Hidden");
$("#SingleArticle").html("");
proxy.getArticle(link, articleRetrieved, serviceDefaultErrorHandler);
}
|
That’s all! Now you have a working page doing exactly the same as it did before only using our own javascript proxy without any dependencies on the Microsoft proxy or the MS Ajax library.
The end result is as expected identical to the one before:

Source Code
Can be downloaded here.
Resources
- Simplify calling ASP.NET AJAX services from jQuery
- Improving jQuery’s JSON performance and security
- Never worry about ASP.NET AJAX’s .d again
- WCF and JSON Services
