March 2009 - Posts
If you are not familiar with it, CodeStock is June 26-27 in Knoxville, TN. If you have not submitted your talk, do so now. Run, don't walk over to
http://www.codestock.org/Speakers.aspx and submit your session. Session submissions are due by the end of today (March 31).
I've been working on this application to run on Windows Azure. I wanted to share a few things that I have learned. I'm not sure if I have missed these being covered else where, but I want to bring them up here for my own knowledge. I find that I remember things much better if I blog them than if I put them on twitter.
- Resource not found for the segment 'ObjectTableName." Steve Smith has a good blog post on this at http://stevesmithblog.com/blog/azure-table-storage-gotcha/. I got this message, followed Steve's instructions and bang, still go the message. WTF is that about! Anyway, I found that I had to reset the table storage through the azure development storage applet and then recreate the tables from the objects in Visual Studio. Once I did that, things seemed to work better. Yippee!
Another note, that you can get this error when you operate on a LINQ query that returns no objects.
- I was running queries that were not returning any data. WTF is that about! Then it hit me, LINQ doesn't return data until you actually ask for that data. I need to force LINQ to send me some data in some situations. How can I force this to occur? I saw that some of my queries were returning data and some were not. I started playing around and found that if I called .ToList<T>() after my query that the data always came back to me. I figure that was a step in the right direction.
- Azure Development Tools use Sql Server Express on the local development machine to store data during development. I decided to look and see what is happening. Guess what, you can connect up and see your data just like you thought you could in any application. Also, you can use Sql Server tools to see WTF is going on. I used that to figure out the issue above.

- DateTime.Now vs. DateTime.UtcNow. Have you used DateTime.Now in an Azure query? It works just fine when you are running in the local development fabric. Deployed to the azure hosted fabric and I got an error. You can't quite connect VS.NET to the hosted fabric to see what is going on. After lots of testing, I changed the query I was doing to use DateTime.UtcNow andlow and behold my app started posting messages to twitter from the hosted fabric.
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/25/more-things-that-i-have-learned-with-azure.aspx
I've been working on setting up my VPC for Azure's March CTP. This
is a fresh install. I had everything installed. Here are a couple of
gotchas that you have to remember:
- SqlExpress needs to be
running. I had the .\SqlExpress service turned off in my archived
vpc. With the service off, the dev tools can't see the database
service so they fail.
A database can be setup by right clicking on your cloud service and selecting "Create Test Storage Tables."- With
a new installation, windows communication foundation (WCF) is most
likely not setup. You may need to setup calls to WCF. To setup WCF,
you may need to login as an Administrator and run "ServiceModelReg -i"
Original Url:
http://morewally.com/cs/blogs/wallym/archive/2009/03/24/more-gotchas-from-the-trenches-with-azure.aspx
One of the interesting new objects in ASP.NET 4.0 AJAX is the
DataView. its a client side object which is associated with a display
tag of some type. In my examples, I've been using a table. I assume
it could be anything. One of the features of the DataView is the
ability to call an event each time a record is bound to the DataView.
This is similar in concept to the server side asp.net grids which have
the OnRowDataBound events (or similarly named). One of the common
scenarios that I see is to have a drop down list box inside of a
record. This could represent typically anything. As I was working
through the DataView, I thought about some type of efficient way to
cache the data. In my scenario, the data is constant across the rows,
so caching it is fairly easy. Anyway, here goes:
- I call the method to get my data first before doing anything else in my page load client side event:
TwitterService.GetFriends(userName, StoreFriendsCallBack);
TwitterService.GetUserTimeLine(userName, TwitterServiceCallBack, TwitterServiceFailure); - In side of my StoreFriendsCallBack method, all I do is store my data to a global js variable I call dd.
function StoreFriendsCallBack(result) {
dd = result;
} - Finally,
I test to see if my dd (dropdown) object has any data or not. If it
has data, I use it, if not, then I go ahead and call back to the server
to get my data.
if (dd == null) {
TwitterService.GetFriends("More_Wally", FriendsCallBack, null, userCtx);
}
else {
DisplaySelect(dd, userCtx);
}
I used C# and WCF, but I could have just as easily used an ASMX web service. This code is fairly simple. No I didn't write it initially.
I found it online (Hey, we all have to start somewhere). I massaged it
a little to fit my needs and boom, here it is. I have decided to leave
the comments for the original code sample in the post. Note: This code
will not run as listed. You have to have a password. This code has
that as a shared variable, but I'm not showing that to you, seriously.
I hope that this is of some help to you.
[OperationContract]
public void SubmitUserStatus(string username, string tweet)
{
// encode the username/password
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
// determine what we want to upload as a status
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
// connect with the update page
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");
// set the method to POST
request.Method = "POST";
// thanks to argodev for this recent change!
request.ServicePoint.Expect100Continue = false;
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " + user);
request.ContentType = "application/x-www-form-urlencoded";
// set the length of the content
request.ContentLength = bytes.Length;
// set up the stream
Stream reqStream = request.GetRequestStream();
// write to the stream
reqStream.Write(bytes, 0, bytes.Length);
// close the stream
reqStream.Close();
}
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/20/twitter-api-submit-a-post-in-c.aspx
Yeah, so some of my friends asked me why I am not using a twitter library instead of calling the api directly. Yeah, I'm wondering that to. Seriously, the reason why I am doing that is that .net libraries to call out to twitter that I tried under VS 2008, did not work with Windows Azure. These libraries seemed to generate a security exception. Given azure's security requirements being a little more than regular asp.net, I decided to just drop the search for a library and make my calls on my own. Not sure if its a good decision or not, but its what I did.
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/18/why-am-i-writing-against-the-twitter-api-directly.aspx
PS. I hear that Full Trust and Native Code support are coming to Azure.
As I was doing my talk on Saturday at the Atlanta Code Camp on data binding at the Atlanta Code Camp, there was a question about the DOM being updated. The question arose wondering if the DOM itself was really being updated. Thanks to Paul Lockwood, he said that Firebug in Mozilla could tell us if it was being updated or not. I pulled out FF 3 with Firebug, opened the page, started to drill through the code, and bang, there was the grid. I did not know that Firebug had that feature. Thanks to Firebug for showing that and thanks to the ASP.NET AJAX team for dynamically updating the DOM.
PS. My buddy Dave Ward told me that it's possible for Firebug to display DOM changes only.
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/19/asp-net-4-0-ajax-dynamic-update-to-the-dom.aspx
I tried writing some code to send a direct message using the Twitter
API. It was a FAIL. I did some searching in google, and found this
method below listed in a google group. I didn't write it, but it
works, so enjoy. I plugged the method into my WCF Service and it just
worked.
[OperationContract]
public void DMSend(string username, string recipient, string tweet)
{
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("http://twitter.com/direct_messages/new.xml?user="
+ recipient + "&text=" + tweet);
req.Method = "POST";
req.Credentials = new NetworkCredential(username, password);
req.ContentLength = 0;
req.ContentType = "application/x-www-form-urlencoded";
WebResponse response = req.GetResponse();
}
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/19/twitter-api-sending-a-direct-message-in-c.aspx
When I first worked with the original ASP.NET 2.0 AJAX, some folks
told me that it only worked with IE, which was wrong then. I decided
to take a look at ASP.NET 4.0 Preview 4 in Chrome and Firefox. I
looked at my an example dataview i'm working with in my azure
application. Low and behold, it looked the same in IE8, Firefox 3, and
Chrome 2 beta. Here's a display of all of them.
IE8:
Firefox 3:

Chrome 2 beta:
There may be something that doesn't work right outside of IE, but I haven't seen it so far.
I needed to call the Twitter API and get a list of friends. I
thought I could do something similar to getting a list of posts, but
alas, I had some stupid error in my linq to xml code. I futzed around
with it for days to no avail. Finally, I decided it was just easier to
iterate through the XML using an XmlNode and fill my objects that way.
Hey, it just worked. Like my previous example, this code uses C# and
is in a WCF Service. Note: As displayed, the code doesn't work, you
will have to supply a password.
[OperationContract]
public Friends[] GetFriends(string username)
{
string url = "http://twitter.com/statuses/friends.xml";
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
Friends frd;
List<Friends> lf = new List<Friends>();
request.Method = "POST";
request.Credentials = new NetworkCredential(username, password);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseString = reader.ReadToEnd();
reader.Close();
XmlDocument xmld = new XmlDocument();
xmld.LoadXml(responseString);
XDocument document = XDocument.Parse(responseString);
foreach(XmlNode xmln in xmld.SelectNodes("users/user"))
{
frd = new Friends();
frd.id = Convert.ToInt32(xmln["id"].InnerText);
frd.name = xmln["name"].InnerText;
frd.screen_name = xmln["screen_name"].InnerText;
lf.Add(frd);
}
return (lf.ToArray());
}
My custom object which I am streaming back looks like this:
[DataContract]
public class Friends
{
[DataMember]
public string name { get; set; }
[DataMember]
public string screen_name { get; set; }
[DataMember]
public int id { get; set; }
}
Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/18/twitter-api-get-a-list-of-your-friends-in-c.aspx
More Posts
Next page »