Sep 7, 2009

Microsoft Azure .NET Services

The upcoming series of posts are dedicated to “Herr Hannes”.
Starting today with the Microsoft Azure platform is Mario, 7.9.09.

The main drivers to go into the Cloud are: Operation, Maintenance, Quality-of-Services, Security.

clip_image001

Windows Azure Platform (source blogs.msdn.com)

Introduction

Azure
  • Microsoft Windows Azure (Platform; compute/store/manage; open for 3rd party hosters)
    vs. Azure Services (Live Services, .NET Services, SQL Services, SharePoint Services, Dynamics CRM Services and more)
  • for application and service hosting (in the cloud)
  • Pricing & Licensing (2000 VM hours compute, 50 GB storage, 20 GB network throughput / day), then
    compute 0.12$/hour, storage = 0.15$, SQL Azure 1 GB 10$/month or 100$/month,
    .NET Services 0.15$/100k messages, 0.10$ bandwidth/GB
.NET Services
  • for .NET, Java, Ruby; REST, SOAP, RSS, ATOM. Focus on application integration and access control
    Quality of Services, flexible scale out
Service Bus
  • Patterns: Service Registry, Connectivity (relay or direct), pub/sub
    "abge-space-ter ESB", NAT/firewall traversal, HTTP and TCP (using ports 808, 818, 819, 828)
    Addressing: [http|sb]://solution.servicebus.windows.net/project/serviceXy , new schema prefix "sb" for TCP
      One-way connection relays,

Service Connectivity (source: msdn.microsoft.com)

Azure is building on existing assets such as WCF. WCF is enhanced in two areas:

  1. bindings (see below) and
  2. behaviors

WCF Bindings and new service bus Relay bindings:

BasicHttpBinding (BasicHttpRelayBinding)
WebHttpBinding (WebHttpRelayBinding)
WSHttpBinding (WSHttpRelayBinding)
WS2007HttpBinding (WS2007HttpRelayBinding)
WSHttpContextBinding (WSHttpRelayContextBinding)
WS2007HttpFederationBinding (WS2007HttpRelayFederationBinding)
NetTcpBinding (NetTcpRelayBinding)
NetTcpContextBinding (NetTcpRelayContextBinding)
n/a  (NetOnewayRelayBinding)
n/a  (NetEventRelayBinding)

Resources

So let’s do some hands-on. There’s a sample called EchoService in the SDK.

As always with WCF you create a contract:

[ServiceContract(Name = "IEchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
public interface IEchoContract
{
    [OperationContract]
    string Echo(string text);
}

implement the contract:

[ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
class EchoService : IEchoContract
{
    public string Echo(string text)
    {
        Console.WriteLine("Echoing: {0}", text);
        return text;           
    }
}

Configure the self-hosting console application in app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <!-- Application Service -->
     
<service name="Microsoft.ServiceBus.Samples.EchoService">
        <endpoint contract="Microsoft.ServiceBus.Samples.IEchoContract"
                  binding="netTcpRelayBinding" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Do the self-hosting:

// Determine the system connectivity mode based on the command line
// arguments: -http, -tcp or -auto  (defaults to auto)
ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args);

Console.Write("Your Solution Name: ");
string solutionName = Console.ReadLine();
Console.Write("Your Solution Password: ");
string solutionPassword = ReadPassword();

// create the endpoint address in the solution's namespace
Uri address = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, "EchoService");

// create the credentials object for the endpoint
TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior();
userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword;
userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName;
userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;

// create the service host reading the configuration
ServiceHost host = new ServiceHost(typeof(EchoService), address);

// create the ServiceRegistrySettings behavior for the endpoint
IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);

// add the Service Bus credentials to all endpoints specified in configuration
foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
{
    endpoint.Behaviors.Add(serviceRegistrySettings);
    endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);               
}

// open the service
host.Open();

Console.WriteLine("Service address: " + address);
Console.WriteLine("Press [Enter] to exit");
Console.ReadLine();

// close the service
host.Close();

On the client side we are doing a similar thing using the ChannelFactory:

// create the service URI based on the solution name
Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, "EchoService");

// create the credentials object for the endpoint
TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior();
userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword;
userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName;
userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;

// create the channel factory loading the configuration
ChannelFactory<IEchoChannel> channelFactory = new ChannelFactory<IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri));

// apply the Service Bus credentials
channelFactory.Endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);

// create and open the client channel
IEchoChannel channel = channelFactory.CreateChannel();
channel.Open();

So what was added to WCF for Azure:

  • the binding (NetTcpRelayBinding)
  • a cloud rendez-vouz address (“sb://mleder.servicebus.windows.net/EchoService”)
  • a behavior (TransportClientEndpointBehavior) to pass Azure solution credentials
  • a behavior for the registry (ServiceRegistrySettings)

Behaviors and credentials above can also be done using config files and the Microsoft Service Configuration Editor tool:

image 

However, the new TransportClientEndpointBehavior has only one property (CrendentialType) that can be edited. Not very useful; hope this will be improved until release.

4 comments: