Themelia Pro A powerful new development platform built on ASP.NET.
 
Using Service Aliases
 
 

In addition to the other endpoint types, Themelia Pro provides another endpoint type called the service alias, which, as the name, suggests, aliases WCF services.  WCF gives us an incredibly powerful service infrastructure that crosses borders into the world of the web.  By creating JSON or XML-based WCF services for web use we can provide for a myriad of solutions and with Themelia we can make those services look good.  By mapping Themelia Pro endpoints with WCF endpoints, we can make WCF endpoint access a lot smoother.

Before any examples are given its important to note two important things about this feature:  first, this feature is for web-based services and BasicHttpBinding services, not for non-web related WCF services like federates services, TCP services, or even WsHttpBinding services.  Second, this feature requires IIS7 in integrated mode.  If you are using Windows Server 2008 and work with Silverlight WCF services, then this is perfect for you.

Like the other types of aliases, service aliasing is setup via the "parameter" attribute as the following example shows:

<themelia.web>
  <webDomains>
    <add>
      <endpoints>
        <add matchType="contains" type="ServiceAlias" text="/service/contact/" parameter="/Contact.svc" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

Now instead of giving out the endpoint /Contact.svc, you just give them /service/contact/.

RSS Example

In addition to the many different data service mechanisms for which WCF provides, it also supplies awesome REST functionality and an amazing syndication feature.  The combination of these two concepts allows you to create RSS feeds with little effort.  The path to these RSS feeds also accept parameters so your RSS service knows how to generate the feed.  For example, while many people use FeedBurner to provide the world with a feed for a blog feed, FeedBurner must be provided with an original.  FeedBurner would be the only party with the original (lest the entire point of aliasing it be pointless.)  The feed given to them may look something like the following:

http://www.tempuri.com/Service_/Feed.svc/GetFeed/B166D85E-5B55-42a5-995E-F9D9958406E5/10

Now regardless if you are creating RSS feeds, the point remains that WCF provides the ability to create REST based services where the URL provides the parameters to the internal method.  Therefore, URLs can get really long, really fast.  Fortunately, as we have already seen, Themelia helps clean these up.  Here's how we can dramatically shrink the above REST-based RSS URL:

<themelia.web>
  <webDomains>
    <add>
      <endpoints>
        <add matchType="contains" type="ServiceAlias" text="/feed.xml" parameter="/Service_/Feed.svc/GetFeed/B166D85E-5B55-42a5-995E-F9D9958406E5/10" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

All that stuff is now packed into /feed.xml.  You can do the some for the other types of WCF web-based services as well as for WCF BasicHttpBinding services.

Regular Expression Pattern Matching

One important thing you can do with service aliasing (as well as in page aliasing) is use a regular expression to create patterns of matching.  This allows you to setup a single alias for multiple services.  For example, instead of aliasing /service/comment to /Service_/Comment.svc, /service/label to /Service_/Label.svc, and /service/author to /Service_/Author.svc, you may just alias /service/([a-z]+)/([a-z]+) to /Service_/$1.svc/json/$2.

By way of example, let's say this is our WCF configuration:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="JsonPersonServiceBehavior">
        <enableWebScript/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <services>
    <service name="Sample.Web.Service.PersonService">
      <endpoint address="json"
                behaviorConfiguration="JsonPersonServiceBehavior"
                binding="webHttpBinding"
                contract="Sample.Service.IPersonService"/>
    </service>
  </services>
</system.serviceModel>

With this we can use the following as our Themelia configuration:

<themelia.web>
  <webDomains>
    <add defaultPage="/Page_/Information/Person.aspx">
      <endpoints>
        <add matchType="contains" type="ServiceAlias" text="/service/([a-z]+)/([a-z]+)" parameter="/Service_/$1.svc/json/$2" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

In this example, we are capturing the service name ($1) as well as the service operation ($2), thus allowing /service/person/GetPersonList to alias "/Service/person.svc/json/GetPersonList, which is exactly what's normally required.  We needed to do it this way because our WCF configuration has set a relative endpoint address ("json") for our service.  Since "json" is part of the internal mechanics of the system that has absolutely no meaning in the real world, the Themelia configuration removes it by capturing around it.

Loose Coupling

One extremely important point about rewriting services relates to coupling.  Tight coupling is a fast way to destruction.  When your physical path matches your logical path, you have a potential disaster on your hands.  When the world is accessing /Contact.svc, what happens when you need to move that file?  People are using this thing, so you can't exactly move it to /Service_/Contact.svc or anything.  Therefore, service rewriting isn't just there to make the URL pretty, it helps save you from insanity later on.

Also, be very careful with excessive regular expressions.  By mapping an entire group of endpoints to a group of services, you are creating a very massive link from the logical to the physical world.  This is very dangerous and defeats the entire purpose of using Themelia Pro, to separate the logical from the physical world.  This is also why Themelia Pro does not allow regular expressions in other endpoints.  Themelia Pro is used to separate the physical from logical world, regular expression maps would do nothing less than create an emulation of that.