text: I’m trying out Azure Training Kit examples to study cloud stuff that should hit the streets (or sky) later this year. I faced some trouble when trying to connect with .Net Service Bus using settings mentioned in examples (netTcpRelayBinding and CardSpace). I tried hard but CardSpace authentication failed every time. My final solution was simple: I moved to username and password authentication scheme.
  I found some very good information from David-Pur Maor’s blog entry Azure .NET Services – A Twitter Service Bus. There is one more reason why you should read this entry – it introduces a Twitter service bus. :)
  Basically we need to change the configuration files so there is no information about authentication schemes. Service configuration file looks like this.
  <?xml version="1.0" encoding="utf-8" ?>
  <configuration>
  <system.serviceModel>
  <bindings>
  <netTcpRelayBinding>
  <binding name="default" />
  </netTcpRelayBinding>
  </bindings>
  <services>
  <service name="Service.EchoService">
  <endpoint name="RelayEndpoint"
  contract="Service.IEchoContract"
  binding="netTcpRelayBinding"
  />
  </service>
  </services>
  </system.serviceModel>
  </configuration>
  As a next thing we have to modify Service and Client Program.cs files. You can take contents of these files with copy and paste (I made no corrections to line breaks because you anyway delete them after copying this code).
  using System;
  using System.ServiceModel;
  using Microsoft.ServiceBus;
  namespace Service
  {
  class Program
  {
  static void Main(string[] args)
  {
  Console.Write("Please enter the solution name to use in this lab: ");
  var account = Console.ReadLine();
  Console.Write("Please enter the solution password: ");
  var passwd = Console.ReadLine();
  var address = ServiceBusEnvironment.CreateServiceUri("sb", account, "EchoService");
  var host = new ServiceHost(typeof(EchoService), address);
  var behavior = new TransportClientEndpointBehavior();
  behavior.CredentialType = TransportClientCredentialType.UserNamePassword;
  behavior.Credentials.UserName.UserName = account;
  behavior.Credentials.UserName.Password = passwd;
  foreach (var endpoint in host.Description.Endpoints)
  {
  endpoint.Behaviors.Add(behavior);
  }
  host.Open();
  Console.WriteLine("Service address: " + address);
  Console.WriteLine("Press [Enter] to exit");
  Console.ReadLine();
  host.Close();
  }
  }
  }
  Program.cs (Client)
  namespace Client
  Console.Write("Enter the name of the solution you want to connect with: ");
  var solutionName = Console.ReadLine();
  var pass = Console.ReadLine();
  var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, "EchoService");
  var address = new EndpointAddress(serviceUri);
  var channelFactory = new ChannelFactory<IEchoChannel>("RelayEndpoint", address);
  behavior.Credentials.UserName.UserName = solutionName;
  behavior.Credentials.UserName.Password = pass;
  channelFactory.Endpoint.Behaviors.Add(behavior);
  IEchoChannel channel = channelFactory.CreateChannel();
  channel.Open();
  Console.WriteLine("Enter text to echo (or [Enter] to exit):");
  var input = Console.ReadLine();
  while (!String.IsNullOrEmpty(input))
  try
  {
  Console.WriteLine("Server echoed: {0}", channel.Echo(input));
  }
  catch (Exception e)
  Console.WriteLine("Error: " + e.Message);
  input = Console.ReadLine();
  channel.Close();
  channelFactory.Close();
  David’s Twitter example code contains one more hidden gem – method you can use to let users safely insert passwords on command line. No characters are shown, only asterisks.
  Client.
  I have class library that contains some XML-files as embedded resources. Reading these files at runtime is very easy. It takes only couple of lines of code.
  Let’s assume we have class library MyExamples.TestLibrary where we have XML-file called mappings.xml. When we compile our class library then mappings.xml will be put inside assembly as embedded resource. Here is the code to read this XML-file (you need to import System.IO, System.Reflection and System.XML namespaces).
  var fileName = "MyExamples.TestLibrary.mappings.xml";
  var assembly = Assembly.GetExecutingAssembly();
  var stream = assembly.GetManifestResourceStream(fileName);
  if (stream == null)
  throw new FileNotFoundException("Cannot find mappings file.", fileName);
  var doc = new XmlDocument();
  doc.Load(stream);
  //.
  Another new SEO feature that ASP.NET 4.0 introduces is support for meta description and keywords. I think these are the most abused SEO features ever and search engines are very careful when considering these meta tags but I am very sure that there are still engines that respect those tags and that’s what makes these new features very useful.
  Let’s see now how to set meta keywords and description to page. At first let’s create empty ASP.NET page and let’s see through browser the mark up of this page. Mark up should look something like this.
  Now let’s write Load event for page. In this event we set meta description and keywords programmatically. Just take the following code in language you prefer.
  protected void Page_Load(object sender, EventArgs e)
  Page.MetaDescription = "This is my rabbits page";
  Page.MetaKeywords = "rabbit, rabbits, bunny, bunnies";
  VB.NET
  Let’s run web application again and see page source through browser again. You should see something like this.
  There is one little thing that is annoying for me: meta tags are not splitted to separate lines. To make mark up easier to read I had to insert line breaks manually. But server-side code, as you can see, is simple and straightforward.
  ASP.NET 4.0 introduces some SEO improvements. Response has now new method called RedirectPermanent(). This method performs same redirect as Response.Redirect() but it uses response code 301. You can find more information about HTTP response codes from HTTP 1.1 specification, chapter 10. Status Code Definitions.
  Response.Redirect() returns 302 to browser meaning that asked resource is temporarily moved to other location. Permanent redirect means that browser gets 301 as response from server. In this case browser doesn’t ask the same resource from old URL anymore – it uses URL given by Location header.
  To illustrate difference between Response.Redirect() and Response.RedirectPermanent() let’s look at simple example. We need one usual ASP.NET Web Application with Global.asax file. In Global.asax file we have to implement BeginRequest() method.
  protected void Application_BeginRequest(object sender, EventArgs e)
  if (Request.FilePath == "/our-products.aspx")
  Response.Redirect("/products.aspx", true);
  if (Request.FilePath == "/about-us.aspx")
  Response.RedirectPermanent("/about.aspx", true);
  Now let’s run our web application and make the following requests:
  In both cases we will be redirected but redirections are different. Here is my little mix of FireBug outputs for these requests and I think it is very self describing.
  Response.RedirectPermanent() has also overload with one parameter, just like Response.Redirect() does. If you have pages that exist in search engines but are moved to other location in your application then Response.RedirectPermanent() helps you build redirection controlling mechanism that likes to search engine spiders.
  During.;
  VB.NET);
  When we run this code we get expected results..
  Before I say anything else let’s compare performance of those implementations.
  Now let’s see how these implementations perform. I am sure that less experienced programmers will check if these implementations give same results and they will try them with pretty small inputs. But… look at the results.
  Performance results of recursive and flat implementations of
  Fibonacci numbers algorithm..
  Currently there is no good method in SharePoint for deleting all items from list. But there are solutions that need this kind of functionality. During one of my projects I wrote extension method for SPList that removes all items from it.
  public static void Clear(this SPList list)
  var count = list.ItemCount;
  for (var i = count - 1; i >= 0; i--)
  var item = list.GetItemById(i);
  item.Delete();
  list.Update();
  ();
  1
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  21
  31
  41
  51
  61
  71
  81
  91
  100
  10
  11
  1
  14
  12
  13
  16
  17
  18
  19
  21
  31
  15
  51
  61
  41
  71
  81
  100
  91.