Monday, December 17, 2007

ASP.NET MVC Site & Items Templates!

After two days of learning and understanding the new Microsoft ASP.NET MVC technology, I was very interested in use its cappabilities in some new sites.

I wanted to implement simple Web Sites (no Applications), but this release does not include templates for sites, only apps. Taking a look of some blog posts from Jason, I found a excellent template for sites with Visual Web Developer 2008 .

This helped me with that I needed at that time, but I also like the missing templates for items that we use when build applications using the ASP.NET MVC Framework. To make available these, I convert the MVC templates to be compatible with Visual Web Developer, including the site templates.
I has packed them in a Visual Studio Installer to make more simple the installation. Download all the templates by language here:
I hope this helps,
regards,

Wednesday, July 18, 2007

Dynamic Configuration for WCF Service Base Address

A Base Address works an important role, when you are creating a Service with the Windows Communication Foundation API. This allows define the root address to parse the EndpointAddress, if the specified EndpointAddress Uri is a relative Uri. This is, only when the Endpoint Binding Protocol Scheme and the Base Address Uri Scheme match.

Then if you are creating a ServiceHost, you have the posibility of specify Service Base Addresses directly into your code, then you can add the respective endpoints in the host application configuration file. For Example:

// Sets the Base Address
Uri[] baseAddresses = new Uri[]{
        new Uri("net.tcp://localhost:1234/Intranet"),
        new Uri("http://localhost:5678/Internet")
    };
ServiceHost AccountingHost =
    new ServiceHost(typeof(AccountingImplementation), baseAddresses);
<configuration>
  <system.serviceModel>
    <services>
      <service name="HostSample.AccountingImplementation">
        <endpoint address="Ecuador"
                  binding="netTcpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="USA"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="England"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

In a company that need to change regularly the service base addresses, to specify base addresses directly in code is a bad practice, because this are static by default, and they all need be dynamics address!. In some cases i look many developers using the AppConfig Section in a config file or a custom store, to resolve the problem, as this Example:

// Gets the Uri Addresses from an AppSetting element
Uri[] baseAddresses = new Uri[]{
    new Uri(ConfigurationManager.AppSettings["tcpBaseAddress"],
    new Uri(ConfigurationManager.AppSettings["httpBaseAddress"]
};
ServiceHost AccountingHost = 
    new ServiceHost(typeof(AccountingImplementation), 
        baseAddresses);
<configuration>
  <appSettings>
    <add key="tcpBaseAddress" value="net.tcp://localhost:1234/Intranet"/>
    <add key="httpBaseAddress" value="http://localhost:4567/Internet"/>
  </appSettings>
  <system.serviceModel>
    <services>
      <service name="HostSample.AccountingImplementation">
        <endpoint address="Ecuador"
                  binding="netTcpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="USA"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="England"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Ok, the service really works fine, returning the expected results when use this implementation, and my IT friends are happy. But, What happens if i have more than one service in the current app domain or were added new contracts using a new base addresess for a MSMQ Address for example?, Do you have an answer for it?

Mmm... I need add a lot of elements added into appSettings Sections, or if i use a custom store, add the base addresses and endpoints dynamicly, then load it before that the service will be started. This is not hard to design and develope, but will be waste important time for me.

But, WCF have a good solution for it, is more faster and more easy to implement that any other way, because this load the baseAddreses when read the service elements from the host configuration file. This is an example:

// I'm not add the service base addreses because they are
// dynamicly loaded from the configuration file
ServiceHost AccountingHost = new ServiceHost(typeof(AccountingImplementation));
<configuration>
  <system.serviceModel>
    <services>
      <host>
        <baseAddreses>
          <add baseAddress="net.tcp://localhost:1234/Intranet"/>
          <add baseAddress="http://localhost:4567/Internet"/>
        </baseAddreses>
      </host>
      <service name="HostSample.AccountingImplementation">
        <endpoint address="Ecuador"
                  binding="netTcpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="USA"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
        <endpoint address="England"
                  binding="wsHttpBinding"
                  contract="HostSample.IAccounting" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

The Service Base Address and Endpoint Address are completly dynamic, using directly a configuration file, it is simply the best.

NOTE: You can register only one base address by service endpoint binding type.

Windows Communication Foundation, a Microsoft Services Oriented Framework

Over 13 or 14 months, i had a conversation with my brother -Marlon Ramirez-. We comment us about distributed technologies and our world (at these moment), and he say me that "to develope distributed applications is very hard, because exists many technologies, but they resolve a problem in a specified scenario. But what happens if you find deploy more than one of these technologies in your solution?"

I answer: "yes to deploy more than one distributed technology is really a very hard work, because you need to have skills for every technology, and at the same time, you will not be sure if this is a good solution for each case. Then we need to have certain architecture patterns skills to determine the best form to implement a generic definition when using every technology then call the required technology.".

But for a simple developer to make this is more work and more time. On the last years, Microsoft has been developing a new Framework, combining the opinions and the feedback of customers, partners and company employees. This framework project initially was code-named as "Indigo", being oficially named as "Windows Communication Foundation" in the Microsoft PDC'05. WCF unifies all the best Microsoft Distributed Technologies (Remoting, Web Services, Message Queue, Enterprise Services, etc) helping us to develope service-oritented applications, increasing the developer productivity, where you can combine the features of all technologies such as transactions, transports, security, etc.

Welcome!

Hi, my name is Ronald Ramirez. I'm a developer based on El Triunfo, a small town located at Guayas, Ecuador. I already had a blog at wdevs resources website, but because the problems with their website, I return to write at this place.

I have a blog in Spanish language located at http://ecuador.latindevelopers.net/blogs/dlanorok. My main interests are Solutions Architecture, Distributed Technologies and Programming Languages. I will write about hot .NET technologies and languages, SQL Server and so on.

Then, Welcome to my new blog,

Best Regards,

Ronald Ramirez