RSS feed blog search engine
 

nunos's Blog  
Released:  3/7/2009 5:11:02 PM  
RSS Link:  http://blogs.msdn.com/nunos/rss.aspx  
Last View 2/3/2012 10:15:58 PM  
Last Refresh 3/8/2010 9:50:55 AM  
Page Views 189  
Comments:  Read user comments (0)  
Report violation Report a violation or adult content
Save It  



Description:



A simple, yet interesting scenario: hosting a WCF service on Windows Azure.. A simple, yet interesting scenario: creating a database on Microsoft SQL Azure.. A simple, yet interesting scenario.. New life as a Developer Evangelist..


Contents:

A simple, yet interesting scenario: hosting a WCF service on Windows Azure

In the previous post, I created a simple database that lives in the cloud, using the Microsoft SQL Azure platform. Now, because I want to have a Silverlight client using it, I will develop a couple of services that will be hosted in Windows Azure, to provide both read and write access to my data.

I will create both a traditional WCF service and a REST service using ADO.NET Data Services. Both are solid approaches to solving our problem with different characteristics. WCF services are what is typically refered to as Fixed Contract services, in the sense they provide a structured set of “black boxes” that receive a specific input and return an expected result. REST services are open-ended ways of interacting with data, awarding more flexibility in a less formatted way.

So, after installing the Windows Azure SDK, I open up Visual Studio and create a new type of project that is made available to me:

After that, I’m asked to create a project inside my solution, which relates to a Role inside Windows Azure:

In my solution explorer window I can see that Visual Studio is preparing the solution to be deployed in Windows Azure:

The first thing I need to do is find a way to gain access to the database from my service. I thought it would be really nice if I could do it through Entity Framework so I can speed up my development time. Turns out, the experience is exactly the same as if you were connecting to a SQL Server instance inside your organization. First, I start by adding a new ADO.NET Entity Data Model:

I specify that I want to generate a model from an existing database:

I create the connection to my database as follows:

I then ask to import all the tables in my database and create a model for them:

And the end result is as expected:

So, now I’m ready to use some Entity Framework magic and LINQ to quickly build a service that interacts with my database. In the interface class that describes my service (ITechResources.cs), I define these five methods:

[OperationContract]

List<Technology> GetTechnologies();

 

[OperationContract]

Technology GetTechnologyByName(string techName);

 

[OperationContract]

Technology GetTechnologyById(int id);

 

[OperationContract]

List<Resource> GetResourcesForTechnologyName(string techName);

 

[OperationContract]

List<Resource> GetResourcesForTechnologyId(int id);


I then go into the actual service implementation (TechResources.svc.cs) and implement this interface:

public class TechResources : ITechResources

{

 

    public List<Technology> GetTechnologies()

    {

        throw new NotImplementedException();

    }

 

    public Technology GetTechnologyByName(string techName)

    {

        throw new NotImplementedException();

    }

 

    public Technology GetTechnologyById(int id)

    {

        throw new NotImplementedException();

    }

 

    public List<Resource> GetResourcesForTechnologyName(string techName)



Home  


 
 




Privacy Policy