Choosing a programming language is a personal choice that each programmer gets to make. It is akin to choosing a flavor of ice cream - there are many great options out there, but your favorite flavor is a matter of personal preference.
In Visual Studio 2010, we’ve made several enhancements to our two most popular languages, Visual Basic and C#, to give programmers all the tools they need to build great software no matter which language they prefer.
Visual Basic
The Visual Basic team focused on adding productivity features to the language so developers can get more done in fewer lines of code. The most common customer request for Visual Basic is to remove the underscore (“_”) character when breaking a code statement across multiple lines in most cases. Visual Basic 10 introduces implicit line continuation, which removes the need for the underscore character in most cases.
Function Filter(
ByVal customers As List(Of Customer),
ByVal orderCount As Integer
)
Dim query =
From c In customers
Where c.Orders.Count >
orderCount
Select c
Another new productivity feature is auto-implemented properties. With auto-implemented properties, lines of boiler-plate property implementation code can be replaced with simple one-line declarations. Previously, property declarations often looked like this:
Private _FavoriteFlavor As String = "Butter Pecan"
Property FavoriteFlavor() As String
Get
Return _FavoriteFlavor
End Get
Set(ByVal value As String)
_FavoriteFlavor = value
End Set
End Property
Private _FlavorList As New List(Of Flavor)
Property FlavorList() As List(Of Flavor)
Get
Return _FlavorList
End Get
Set(ByVal value As String)
_FlavorList = value
End Set
End Property
Now property declarations can be declared much more simply:
Property FavoriteFlavor As String = "Butter Pecan"
Property FlavorList As New List(Of Flavor)
Collection initializers and array literals are simpler as well. Collections can now be initialized when they’re declared, and the type of array literals is inferred by the compiler.
Dim toppings = New List(Of String) From
{
"sprinkles",
"chocolate chips",
"strawberries"
}
Dim cones = {"sugar cone", "waffle cone"} 'the type String() is inferred
Visual Basic 10.0 now has better support for lambdas. Lambdas can now contain expressions that don’t return a value, as the Sub keyword indicates below:
Array.ForEach(toppings, Sub(n) Console.WriteLine(n))
Sometimes you’d like to do more complex work inside a lambda declaration. Visual Basic 10.0 supports multiline lambdas. The compiler will infer parameter and return types where possible just like in regular lambdas.
Dim doubleDown = Function(n As String)
If n.StartsWith("s") Then
Return "extra " & n
Else
Return n
End If
End Function
Interoperating with dynamic language code such as Python and Ruby has become simpler in Visual Basic 10.0. For example, the following code snippet calls a method defined in a Python library “math.py”:
Dim mathLib As Object = python.UseFile("math.py")
Dim firstNumber = 44.2
Dim secondNumber = 9.5
mathLib.PowerOf(firstNumber, secondNumber)
C#
C# 4.0’s major themes are interoperability with dynamic programming paradigms and improved Office programmability. Dynamic lookup, a new feature in C# 4.0, allows you to use and manipulate an object from IronPython, IronRuby, JScript, the HTML DOM, or a standard .NET library in the same way, no matter where it came from. Language enhancements such as named and optional parameters and improved support for COM clients give C# developers who are working with Office APIs the same great experience that Visual Basic developers have enjoyed.
Adding the new dynamic keyword to your code allows its type to be resolved dynamically at runtime rather than statically at compile-time. This allows dynamic languages to expose their objects to C# in a way that feels natural to a C# programmer:
dynamic dynamicObject = GetDynamicObjectFromRuby();
dynamicObject.Foo(7);
dynamicObject.Property = "Property value";
dynamicObject[0] = "Indexed value";
Optional method parameters are familiar to Visual Basic and C++ programmers and are now available for C# programmers. Optional parameters are declared with a default value in the method signature, as follows:
private void CreateNewStudent(string name, int currentCredits = 0, int year = 1)
The method above can be called in any of the following ways:
CreateNewStudent("Chloe");
CreateNewStudent("Zoe", 16);
CreateNewStudent("Joey", 40, 2);
To omit the currentCredits parameter value but specify the year parameter, the new named arguments feature (highlighted) can be used. All of the following are also valid calls:
CreateNewStudent("Jill", year: 2);
CreateNewStudent(name: "Bill", currentCredits: 30, year: 2);
CreateNewStudent("Will", currentCredits: 4);
Named arguments are also a great way to write self-documenting calls to your existing methods, even if they don’t use optional parameters.
Learn More
Find out more about Visual Studio 2010’s language enhancements and download samples on the VB Futures site and the C# Futures site. To play with the new features, download and install Visual Studio Beta 1, then join the conversation.
Catch you soon with more updates... on VS 2010
Friday, August 21, 2009
SQL AZURE - New Technology with big changes..
What is SQL Azure?
In short, SQL Azure is simply a Microsoft branding change. SQL Services and SQL Data Services are now known as Microsoft SQL Azure and SQL Azure Database. There are a few changes, but fundamentally Microsoft’s plans to extend SQL server capabilities in cloud as web-based services remain intact. SQL Azure will continue to deliver an integrated set of services for relational databases. The reporting, analytics and data synchronization with end-users and partners also remains unchanged. This makes it most appealing to current users of SQL Server.
Architecture
Some architectural changes have been introduced. While the basic foundation remains the same, support for certain languages and protocols has been discontinued. A relationship data model replaces the ACE (Authority, Container, Entity) data model. In the new model, customer applications gain access through TSQL over TDS. The development environment of those currently using an on-premise SQL server database will continue to be familiar and existing expertise, applications and tools are still applicable.
Programming Model
As a fully relational data model in the cloud has replaced the entity based data model, programming for the new model needs a shift from the ACE programming model to a relational data module, but many SQL Server-like concepts still apply. To access data in the cloud, existing Transact-SQL code can still be used. Developers will need to modify their current Transact-SQL code to interact with the fully relational cloud database service. Current applications may need modification and, in some cases, new applications will need to be created. Existing data access frameworks, such as ADO.NET Data Services can be used without much effort for additional REST and SOAP services.
SQL Azure vs. SQL Server
SQL Server database technologies were used to build SQL Azure. Specifically, the technologies used in critical enterprise and web applications are included. The extensive data platform of SQL Server is capable of handling all data types and the SQL Azure platform introduces many associated capabilities. New relational functionalities are included and extended as services in the cloud .
Availability, self-management and ease-of-use are the highlights of the new service. While only the core RDBMS capabilities of the full SQL Server data platform are presently included, more services are expected to be introduced in the future. Reporting, analytics and ETL will no doubt be available over time. As SQL Server and SQL Azure share the same technologies, bilateral innovation can also be anticipated.
SQL Azure Database
The SQL Azure database service offers a scalable and distributed database hosted in the cloud, and therefore highly available. As HA, backup and recovery, geo-distribution and disaster recovery are built-in, developers do not need to manage any software, but in the case of a dedicated hosted database, they will still be responsible for database software, i.e. for the installation and tasks related to OS and database software.
Windows Azure Table storage
Windows Azure Table storage, offered by SQL Azure Database service, provides a non-relational, scalable, simple structured data storage solution in the Cloud. Structured, semi-structured and unstructured data can be processed and analyzed. As Windows Azure applications are supported in the SQL Azure Database service, it is possible to combine services in accordance with your needs.
SQL Azure Development
SQL Azure’s relational database service supports the T-SQL (Transact-SQL) over TDS (Tabular Data Stream) protocol. The relational data model in the cloud can therefore be used together with current T-SQL developments. The new distributed functionality of the SQL Azure Database in the cloud should provide development cost-savings, as existing applications, tools and expertise can be incorporated. The ability to use the traditional RDBMS data model in the cloud implies that developers should be able to use current interfaces to build new applications, and previous investments in development, training and tools should hold their value.
(image courtesy of http://www.microsoft.com/azure/howdoesitwork.mspx)
Current SOAP and REST based ACE programming models are no longer supported in SQL Azure, but building custom services with ADO.NET Data Services does provide a relatively simple solution for those requiring REST access to their SQL Azure data. For REST based programming model users, who simply require non-relational structured data storage, Windows Azure storage should prove to be an adequate solution.
Visual Studio can be used to create and modify applications for SQL Azure. Additionally, for developing new applications, ASP.NET controls and tools are a useful solution. Web based management tools, to access and manage data in the cloud, and tools and documentation supporting further programming languages, are expected to be introduced in the near future.
In short, SQL Azure is simply a Microsoft branding change. SQL Services and SQL Data Services are now known as Microsoft SQL Azure and SQL Azure Database. There are a few changes, but fundamentally Microsoft’s plans to extend SQL server capabilities in cloud as web-based services remain intact. SQL Azure will continue to deliver an integrated set of services for relational databases. The reporting, analytics and data synchronization with end-users and partners also remains unchanged. This makes it most appealing to current users of SQL Server.
Architecture
Some architectural changes have been introduced. While the basic foundation remains the same, support for certain languages and protocols has been discontinued. A relationship data model replaces the ACE (Authority, Container, Entity) data model. In the new model, customer applications gain access through TSQL over TDS. The development environment of those currently using an on-premise SQL server database will continue to be familiar and existing expertise, applications and tools are still applicable.
Programming Model
As a fully relational data model in the cloud has replaced the entity based data model, programming for the new model needs a shift from the ACE programming model to a relational data module, but many SQL Server-like concepts still apply. To access data in the cloud, existing Transact-SQL code can still be used. Developers will need to modify their current Transact-SQL code to interact with the fully relational cloud database service. Current applications may need modification and, in some cases, new applications will need to be created. Existing data access frameworks, such as ADO.NET Data Services can be used without much effort for additional REST and SOAP services.
SQL Azure vs. SQL Server
SQL Server database technologies were used to build SQL Azure. Specifically, the technologies used in critical enterprise and web applications are included. The extensive data platform of SQL Server is capable of handling all data types and the SQL Azure platform introduces many associated capabilities. New relational functionalities are included and extended as services in the cloud .
Availability, self-management and ease-of-use are the highlights of the new service. While only the core RDBMS capabilities of the full SQL Server data platform are presently included, more services are expected to be introduced in the future. Reporting, analytics and ETL will no doubt be available over time. As SQL Server and SQL Azure share the same technologies, bilateral innovation can also be anticipated.
SQL Azure Database
The SQL Azure database service offers a scalable and distributed database hosted in the cloud, and therefore highly available. As HA, backup and recovery, geo-distribution and disaster recovery are built-in, developers do not need to manage any software, but in the case of a dedicated hosted database, they will still be responsible for database software, i.e. for the installation and tasks related to OS and database software.
Windows Azure Table storage
Windows Azure Table storage, offered by SQL Azure Database service, provides a non-relational, scalable, simple structured data storage solution in the Cloud. Structured, semi-structured and unstructured data can be processed and analyzed. As Windows Azure applications are supported in the SQL Azure Database service, it is possible to combine services in accordance with your needs.
SQL Azure Development
SQL Azure’s relational database service supports the T-SQL (Transact-SQL) over TDS (Tabular Data Stream) protocol. The relational data model in the cloud can therefore be used together with current T-SQL developments. The new distributed functionality of the SQL Azure Database in the cloud should provide development cost-savings, as existing applications, tools and expertise can be incorporated. The ability to use the traditional RDBMS data model in the cloud implies that developers should be able to use current interfaces to build new applications, and previous investments in development, training and tools should hold their value.
(image courtesy of http://www.microsoft.com/azure/howdoesitwork.mspx)
Current SOAP and REST based ACE programming models are no longer supported in SQL Azure, but building custom services with ADO.NET Data Services does provide a relatively simple solution for those requiring REST access to their SQL Azure data. For REST based programming model users, who simply require non-relational structured data storage, Windows Azure storage should prove to be an adequate solution.
Visual Studio can be used to create and modify applications for SQL Azure. Additionally, for developing new applications, ASP.NET controls and tools are a useful solution. Web based management tools, to access and manage data in the cloud, and tools and documentation supporting further programming languages, are expected to be introduced in the near future.
Tuesday, August 4, 2009
WCF 4.0 Features: Part I
Objective:
This article is first part of multi series article on WCF 4.0. This article will list all the new feature of WCF and also will explain in detail Dynamic Service and End Point Discovery feature of WCF 4.0.
A Note:
On 22nd of July 2009, I got a very sweet and new gift from my GOD. So I thought why I should not start something which is new for me on this auspicious day? And I started WCF 4.0. I welcome that gift in my life and welcome WCF4.0 too in my learning. Thanks God.
What are the new in WCF 4.0?
I am listing here, new features in WCF 4.0
Dynamic Service and End Point discovery
Intermediate Routing Pattern ( Generic Routing Services)
Discovery announcement
Simplified Configuration
Protocol bridging and Fault tolerance
Standard End Points.
.svc-less activation of REST services or making REST URI nice.
Readers Note
I will discuss details of each feature in subsequent articles. This article is emphasizing on Dynamic Service and End Point discovery. So please tune in.
Dynamic Service and End Point discovery
Problem:
People say; you need to know only ABC of a service to expose End Point of that service. And client or service consumer needs to know only End Point to consume the service. But wait for a while here, and think; what if? Binding need to change at the service side from basic to WS over HTTP, This is very basic change but to accommodate this client has to update the service again. And this is very much error prone. It is very tedious task to update client about all the basic frequent change at the service side. To solve this issue, there should be some mechanism and that is called End Point Discovery or Dynamic Service.
In absolute technical words
WCF 4.0 supports WS - Discovery standard or protocol.
WS-Discovery Standard
This is a multicast protocol that issues SOAP message over UDP,
WS-Discovery is a Standard that defines a lightweight discovery mechanism for discovering services based on multicast messages. It enables a service to send a Hello announcement message when it is initialized and a Bye message when is removed from the network.
Client or consumer can discover services by multicasting a Probe message to which a service can reply with a ProbeMatch message containing the information necessary to contact the service.
Client or consumer can find services that have changed endpoint by issuing a Resolve message to which respond with a ResolveMatchmessage.
So, we can say WS - Discovery is a UDP based multicast message exchange. This message receives End Point information from Service and uses this as discovery information. Client uses discovery information to discover the available service on the network.
WCF Service Discovery API
WCF provides, WCF Discovery API for dynamic publish and discovery of web service using WS - Discovery protocol. This API helps service to publish them and helps client to find service on the network.
Modes:
Managed Mode:
In managed mode there is a centralized server called a discovery proxy that services use to publish themselves and clients use to retrieve information about available services.
When a new service starts up it sends an announcement message to the discovery proxy.
The discovery proxy saves information about each available service to storage.
When a client must search for a service it sends a Probe request to the discovery proxy and it determines whether any of the services that have been published match the request.
If there are matches the discovery proxy sends a ProbeMatch response back to the client.
The client can then contact the service directly using the service information returned from the proxy.
Ad-Hoc Mode:
There is no centralized server.
Service announcements and client requests are sent in a multicast fashion.
If a service is configured to send out a Hello announcement on start up, it sends it out over a well-known, multicast address using the UDP protocol.
Therefore, clients have to actively listen for these announcements and process them accordingly.
When a client issues a Probe request for a service it is also sent over the network using a multicast protocol.
Each service that receives the request determines whether it matches the criteria in the Probe request and responds directly to the client with a ProbeMatch message if the service matches the criteria specified in the Probe request.
Sample
In this sample, we will create a very basic service and at the client side, first client will discover the service in Ad-Hoc mode and then consume that.
To run and go through this sample, you need Visual Studio 2010 Beta.
To make a service discoverable, a ServiceDiscoveryBehavior must be added to the service host and a discovery endpoint must be added to specify where to listen for and send discovery message
Step 1
Open VS2010. Create a new project. Select project type as Web. From Web Project type choose WCF Service Application Project template.
Step 2
Delete all the code which is generated by Visual studio. After deleting Contract and Service Implantation is as follows.
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetMessage(string msg);
}
}
Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
public class Service1 : IService1
{
public string GetMessage(string msg)
{
return msg;
}
}
}
The above is simple Service Contract and implantation of that.
Step 3:
Open Web.Config file. And modify the System.ServiceModel. Add the code which is highlighted below.
Web.Config
Explanation of Config file
One new End Point is being added.
Kind of newly added End Point is udpDiscoveryEndpoint.
This End Point will be used to discover the service.
ServiceDiscovery behavior is also get added.
Step 4:
Press F5 to run the service. Service will get hosted in ASP.Net web server.
Step 5:
Add a new console project in solution.
Step 6:
Add Reference of System.ServiceModel.Discovery.dll in console project.
Step 7:
Add namespace using System.ServiceModel.Discovery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.ServiceReference1;
using System.ServiceModel;
using System.ServiceModel.Discovery;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DiscoveryClient discoverclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindResponse response = discoverclient.Find(new FindCriteria(typeof(IService1)));
EndpointAddress address = response.Endpoints[0].Address;
Service1Client client = new Service1Client(new WSHttpBinding(), address);
string str= client.GetMessage("Hello WCF 4 ");
Console.WriteLine(str);
Console.ReadKey(true);
}
}
}
Explanation of the code
We are making object of DiscoveryClient class. This class is user to discover available service.
In constructor of this class, we are passing UdpDiscoveryEndPoint of the service.
Then we are calling Find method with contract name as argument to get FindResponse.
Now FindResponse variable having all the available address for contract passed in Find method.
We are creating the client proxy and passing discovered address as argument.
Calling the service operation on the client proxy.
Output:
Conclusion:
In this article, I talked about what are the new features in WCF 4.0. I went into details of Dynamic Service and End Point Discovery. In later articles, I will cover in detail other features as well. Till then, thanks for reading.
Happy Coding!
This article is first part of multi series article on WCF 4.0. This article will list all the new feature of WCF and also will explain in detail Dynamic Service and End Point Discovery feature of WCF 4.0.
A Note:
On 22nd of July 2009, I got a very sweet and new gift from my GOD. So I thought why I should not start something which is new for me on this auspicious day? And I started WCF 4.0. I welcome that gift in my life and welcome WCF4.0 too in my learning. Thanks God.
What are the new in WCF 4.0?
I am listing here, new features in WCF 4.0
Dynamic Service and End Point discovery
Intermediate Routing Pattern ( Generic Routing Services)
Discovery announcement
Simplified Configuration
Protocol bridging and Fault tolerance
Standard End Points.
.svc-less activation of REST services or making REST URI nice.
Readers Note
I will discuss details of each feature in subsequent articles. This article is emphasizing on Dynamic Service and End Point discovery. So please tune in.
Dynamic Service and End Point discovery
Problem:
People say; you need to know only ABC of a service to expose End Point of that service. And client or service consumer needs to know only End Point to consume the service. But wait for a while here, and think; what if? Binding need to change at the service side from basic to WS over HTTP, This is very basic change but to accommodate this client has to update the service again. And this is very much error prone. It is very tedious task to update client about all the basic frequent change at the service side. To solve this issue, there should be some mechanism and that is called End Point Discovery or Dynamic Service.
In absolute technical words
WCF 4.0 supports WS - Discovery standard or protocol.
WS-Discovery Standard
This is a multicast protocol that issues SOAP message over UDP,
WS-Discovery is a Standard that defines a lightweight discovery mechanism for discovering services based on multicast messages. It enables a service to send a Hello announcement message when it is initialized and a Bye message when is removed from the network.
Client or consumer can discover services by multicasting a Probe message to which a service can reply with a ProbeMatch message containing the information necessary to contact the service.
Client or consumer can find services that have changed endpoint by issuing a Resolve message to which respond with a ResolveMatchmessage.
So, we can say WS - Discovery is a UDP based multicast message exchange. This message receives End Point information from Service and uses this as discovery information. Client uses discovery information to discover the available service on the network.
WCF Service Discovery API
WCF provides, WCF Discovery API for dynamic publish and discovery of web service using WS - Discovery protocol. This API helps service to publish them and helps client to find service on the network.
Modes:
Managed Mode:
In managed mode there is a centralized server called a discovery proxy that services use to publish themselves and clients use to retrieve information about available services.
When a new service starts up it sends an announcement message to the discovery proxy.
The discovery proxy saves information about each available service to storage.
When a client must search for a service it sends a Probe request to the discovery proxy and it determines whether any of the services that have been published match the request.
If there are matches the discovery proxy sends a ProbeMatch response back to the client.
The client can then contact the service directly using the service information returned from the proxy.
Ad-Hoc Mode:
There is no centralized server.
Service announcements and client requests are sent in a multicast fashion.
If a service is configured to send out a Hello announcement on start up, it sends it out over a well-known, multicast address using the UDP protocol.
Therefore, clients have to actively listen for these announcements and process them accordingly.
When a client issues a Probe request for a service it is also sent over the network using a multicast protocol.
Each service that receives the request determines whether it matches the criteria in the Probe request and responds directly to the client with a ProbeMatch message if the service matches the criteria specified in the Probe request.
Sample
In this sample, we will create a very basic service and at the client side, first client will discover the service in Ad-Hoc mode and then consume that.
To run and go through this sample, you need Visual Studio 2010 Beta.
To make a service discoverable, a ServiceDiscoveryBehavior must be added to the service host and a discovery endpoint must be added to specify where to listen for and send discovery message
Step 1
Open VS2010. Create a new project. Select project type as Web. From Web Project type choose WCF Service Application Project template.
Step 2
Delete all the code which is generated by Visual studio. After deleting Contract and Service Implantation is as follows.
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetMessage(string msg);
}
}
Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
public class Service1 : IService1
{
public string GetMessage(string msg)
{
return msg;
}
}
}
The above is simple Service Contract and implantation of that.
Step 3:
Open Web.Config file. And modify the System.ServiceModel. Add the code which is highlighted below.
Web.Config
Explanation of Config file
One new End Point is being added.
Kind of newly added End Point is udpDiscoveryEndpoint.
This End Point will be used to discover the service.
ServiceDiscovery behavior is also get added.
Step 4:
Press F5 to run the service. Service will get hosted in ASP.Net web server.
Step 5:
Add a new console project in solution.
Step 6:
Add Reference of System.ServiceModel.Discovery.dll in console project.
Step 7:
Add namespace using System.ServiceModel.Discovery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.ServiceReference1;
using System.ServiceModel;
using System.ServiceModel.Discovery;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DiscoveryClient discoverclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindResponse response = discoverclient.Find(new FindCriteria(typeof(IService1)));
EndpointAddress address = response.Endpoints[0].Address;
Service1Client client = new Service1Client(new WSHttpBinding(), address);
string str= client.GetMessage("Hello WCF 4 ");
Console.WriteLine(str);
Console.ReadKey(true);
}
}
}
Explanation of the code
We are making object of DiscoveryClient class. This class is user to discover available service.
In constructor of this class, we are passing UdpDiscoveryEndPoint of the service.
Then we are calling Find method with contract name as argument to get FindResponse.
Now FindResponse variable having all the available address for contract passed in Find method.
We are creating the client proxy and passing discovered address as argument.
Calling the service operation on the client proxy.
Output:
Conclusion:
In this article, I talked about what are the new features in WCF 4.0. I went into details of Dynamic Service and End Point Discovery. In later articles, I will cover in detail other features as well. Till then, thanks for reading.
Happy Coding!
Subscribe to:
Posts (Atom)