Distribution of functionality Webservice using WCF x
Different technology combined to form WCF. http://wcftutorial.net/Introduction-to-WCF.aspx
ASP.NET - 1 tier distribution http://msdn.microsoft.com/en-us/library/bb547119.aspx
ASP.NET - 2 tier distribution http://msdn.microsoft.com/en-us/library/bb547119.aspx
ASP.NET - n tier distribution http://msdn.microsoft.com/en-us/library/bb547119.aspx
Webservice - SOAP
Remoting – architecture Server and client are both .NET General architecture Proxy, stub, formatting and channel might be changed. Eg is a binary formatting, witch both is supported by TCP og HTTP, more effective than a textbased (XML) Server stub remoting formatter listener Client proxy remoting formatter channel
Remoting service - opportunities Server-activated object (SAO) also called ”Wellknown objects” Singleton: one and only one serverobject for all clients Threadproblem for object data SingleCall: One object per each method call The most easy solution, but less effective State might be keept by using files or database Client-activated object (CAO) Activated: One object per each client lifetime problems – Leasing not supported by IIS
Windows Communication Foundation Architecture http://msdn.microsoft.com/en-us/library/ms733128.aspx
Hosting WCF Side-by-Side with ASP.NET http://msdn.microsoft.com/en-us/library/aa702682.aspx
WCF support the 3 state scenarios Possibly also look for other info about these 3 scenarions on http://www.codeproject.com/KB/WCF/WCFInstance.aspx
WCF host & protocol Wcf might like remoting (singleton og singlecall) be integrated in an asp.net web project and be hosted by the IIS (Internet Information Server), where wcf also might get access for the ASP.NET Session, Application objects ect. Wcf might also be used without using the IIS as selfhosted with other protocols than http. Wcf also support eg json and not only soap, witch not is easy using the older ASP.NET webservices (asmx - technologi)
WCF data protocols WCF might also be configured to communicate by pure XML http://msdn.microsoft.com/en-us/library/bb547119.aspx
WCF setup Service is defined with a ServiceContract on the interface / class witch might be working as service-object, and methods that must be available external for clients must be defined as OperationContract’s Transport-objects must be defined as DataContract and field/property witch might be transported as data as DataMember’s.
Interface with the contract Normally you will define the contract on an interface but can also define this in the class, if you do not want an interface using System.ServiceModel.Web; // contains ServiceContract and OperationContract classes ……….. namespace MyNamespace { [ServiceContract] // Attribut on interfacet public interface IService1 [OperationContract] // Attribut on methods witch should be avaible by the service (on proxy) string GetData(int value); If you want to use session on service in a WcfServiceApplication (can not be used on ASP.NET - website under ISS) must ServiceContract'en added parameters and it looks like this : [ServiceContract(SessionMode = SessionMode.Required)]
Implementation of class for the contract using System.ServiceModel; ………. namespace MyNameSpace { //Default is creattion of a new service-object per each call, but it might be changed //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] // Default //[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] // Remember to threadsafe //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] //Demand wsHttpBinding public class Service1 : IService1 public string GetData(int value) return string.Format("You entered: {0} <{1}>", value + count, s); } Connected markeup Service1.svc file, witch is giving the binding to service1: <%@ ServiceHost Language="C#" Debug="true" Service=“MyNameSpace.Service1" CodeBehind="Service1.svc.cs" %> Remark: PerSession på Wwbserver(IIS) demand wsHttpBinding witch demand adjusting in web.config The .SVC file could also be replaced by setting up endpoint information in web.config
Data transport objects (DTO) If transferring complex objects (not simple types, string and array) then these will be serialized - this should be done using a DataContract - previously you could use [Serializable] - on Web service would only be transferred public fields and public property , corresponding to an XML serialization. using System.Runtime.Serialization; [DataContract] // class could be serialized public class CompositeType { [DataMember] // field shoud be included when serialized bool _boolValue = true; string _stringValue = "Hello "; [DataMember] // property value should be included as data when serialized public int OneInt {private get; set;}
Data transport objecter (DTO) DataContract and DataMember When using these you might yourself include a referece to get the dll part of project