Sunday, November 22, 2009

C# and .NET Programming….On the Apple iPhone!

Many of you may know about an open-source distribution of the .NET platform named Mono. Using Mono, you are able to build cross-platform .NET programs which run under Windows, Mac OS X and various flavors of Linux. As Mono was created using the 334 and 335 ECMA specs, it is completely possible to build-once and run-anywhere.

If you are new to Mono, you may wish to look me up on DevX.  Here you will find a number of articles I authored regarding Mono development.

While Mono is specific to desktop and web-based applications, the Mono development team has recently released a new Mono distribution named MonoTouch. Using this platform, you can build iPhone and iPod touch applications which can be uploaded to the Apple App Store.  Behold!

image

The benefit is that you can build your apps using C# and numerous libraries from the .NET platform. As well, MonoTouch includes specific libraries which allow you to communicate with the underlying OS, and take advantage of specific APIs including the touch screen itself.

Even better, the latest version of MonoTouch integrates with the MonoDevelop IDE!  This IDE is (more or less) a Mac and Linux equivalent of the Window’s centric SharpDevelop IDE (in fact, MonoDevelop is based on the same source as SharpDevelop). For those in the know, MonoTouch also integrates into the XCode IDE

One catch however (there is always a catch, it seems).  Unlike the Mono platform, which is completely free, the MonoTouch platform does come at a cost.  A single user license will run you approximately $400.00 (USD). You can see the break down of each edition of MonoTouch here.

Thankfully, you can obtain a free evaluation of MonoTouch, which exposes the same API core as the commercial product.  The limitation is that the evaluation version only allows you to deploy to the iPhone simulator utility, and cannot be used to upload your app to the App Store.

Here are some links to get you started:

If you have an interest in iPhone / iPod touch development, but would rather *not* learn Objective C, MonoTouch is well worth a download. Moreover, if you have been contemplating buying a shiny new MacPro laptop (gotta love the Windows / Mac dual boot), maybe MonoTouch will be the thing that makes you take the plunge.

Enjoy!

Monday, November 16, 2009

Declaratively Configuring WCF Bindings

One of the bright spots with WCF is the fact that a single service can be exposed using a good number of bindings.  In the System.ServiceModel, there are a number of class types which represent each binding option, including BasicHttpBinding, WsHttpBinding, NetTcpBinding and so forth.

If you are building a custom host for your WCF services, you can easily change the default settings for a given binding object, simply by tweaking properties, constructor arguments, etc (after all, configuring a binding in code is no different than configuring any object).

A second bright spot of WCF, however, is the ability to leverage *.config files to declaratively establish bindings, behaviors, contracts and a slew of additional settings.  For example, the following host *.config file describes a single endpoint a WCF service:

<?xml version = "1.0" encoding = "utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>

      <!-- Here are the ABCs for MyCalc -->
      <service name = "WcfMathService.MyCalc">
        <endpoint address = "
http://localhost:8080/MyCalc"
                  binding = "wsHttpBinding"
                  contract = "WcfMathService.IBasicMath"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

With this, we receive all of the default setting for the wsHttpBinding type.  While this may be just fine for the current example, say you wish to change the timeout settings.  Or wish to configure various security settings.  How exactly can you do this in your markup? Quite simply as it turns out:

<?xml version = "1.0" encoding = "utf-8" ?>
<configuration>
  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name = "myCustomWsHttpBinding"
                     openTimeout = "00:30:00" />
      </wsHttpBinding>
    </bindings>

    <services>
      <service name = "WcfMathService.MyCalc">
        <endpoint address = "http://localhost:8080/MyCalc"
                  binding = "wsHttpBinding"
                  bindingConfiguration = "myCustomWsHttpBinding"
                  contract = "WcfMathService.IBasicMath" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Notice that our configuration file now supports a <bindings> section, where we are able to set properties on a given WCF binding type. Here, we tweaked the openTimeout attribute of wsHttpBinding, but of course you could set any additional attribute values if needed.

Once you have configured the binding you are working with, notice that the <endpoint> now has the ability to opt-in to the customized binding using the bindingConfiguration attribute. Note how the value assigned to this is a dead on match to the name attribute of the <binding> sub element.

Simply stuff, simple blog post.  But hey, sometimes simple is good…