TURKISH BLOG   |  ABOUT ME  |  ARCHIVES  | DELETE LANGUAGE COOKIE

Enes TAYLAN

Mind Hegemony - Mood 1.0 - Total Control Edition

SERVICE ORIENTED ARCHITECTURE (SOA)

clock May 7, 2009 05:14
Service Oriented Architecture (SOA) is a very important concept of our age of big systems and applications. In these big systems and organizations there are different platforms, different operating systems(OS) and communication between these parts is difficult and so important.The solution to this commnunication problem is using services between servers.For example,imagine a situation in Facebook.SOA,Service Oriented ArchitectureFacebook has several servers and each server group has profile information of different people. (I don't know Facebook's organization details but our scenario is most probably correct::))) Also assume that different server groups have different operating systems and different architectures.So the question: how these servers can communicate effectively when you see friend list that each one's profile comes from a different server?The easiest way is using services and construct a Service Oriented Architecture between these servers.How? Using a universal, flexible language (SOAP,XML,both etc.) to communicate.Additinally by sending this information on HTTP wires that is common in almost all systems, problem is solved.Therefore, all server groups send information to a master server via services and master server prepare the list by joining them.However, some extra information other than profile info, in our example , is needed in other words metadata, because XML is so flexible so how to use it in receiving end of the communication can't be known without this guidelines.By using this SOA architecture there is no need to worry about the new server groups, they all can be added to system easily.MICROSOFT's solution in SOA area is WCF(Windows Communication Foundation) (there is also XML based ASP.NET webservice but to build a fully functional service layer, WCF is needed) WCF is a framework and involves other past MICROSOFT SOA technologies (like COM,DCOM,MSMQ etc.) In next post, I will show how to build and consume a WCF service.


BUILDING AND CONSUMING XML BASED WEB SERVICE

clock May 6, 2009 18:50
Building a Web Service means creating a class and expose this class's some methods to web so that a client can consume this web service.To do so create an ASP.NET Web Service in VS2008 by selecting File > New > Web Site and select ASP.NET Web Service. (We will get a data set from a remote machine)

 
Now in solution explorer you have a service.asmx file. Delete it and add a new file to your project.Select Web Service, name it as "Customer.asmx".



Write this code to your Customer.cs in your App_Code directory. 
[WebMethod] //expose our method to the web
public DataSet GetCustomers()   //method to get dataset from a database
{
     SqlConnection conn;
     SqlDataAdapter adapter;
     DataSet result = new DataSet();
     string cmdString = "SELECT * FROM [SELECT * FROM SalesLT.Customer]";  //command string
     conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString);
     adapter = new SqlDataAdapter(cmdString, conn);
     adapter.Fill(result);  //our sqladapter fills the data set
     return result;  //return resulting dataset
}    
Now view in the browser our Customer.asmx You will see ASP.NET's specific page for Web Services.

Click GetCustomer() method.There is SOAP messages and also an invoke button to invoke the WebService.You can check whether the webservice is working or not. At this point we can consume this webservice.Create another ASP.NET website and right click on the project name.Select "Add Web Reference"
 
 
In URL part copy your asmx file's URL. In web reference name part, write Customer Service.Click "Add Reference" Now VS2008 has created necessary classes in the second website to work with web reference.In Default.aspx page add a button a GridView.In click event of button write:
protected void Button1_Click(object sender, EventArgs e) 
{
    CustomerReference.Customer ws = new CustomerReference.Customer(); 
    //CustomerReference is the name we defined when adding Web Reference
    GridView1.DataSource = ws.GetCustomers(); 
    GridView1.DataBind();
}

If there is no exception, when we click the button we should see the results.:)