Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distribution of functionality Webservice using WCF

Similar presentations


Presentation on theme: "Distribution of functionality Webservice using WCF"— Presentation transcript:

1 Distribution of functionality Webservice using WCF
x

2 Different technology combined to form WCF.

3 ASP.NET - 1 tier distribution

4 ASP.NET - 2 tier distribution

5 ASP.NET - n tier distribution

6 Webservice - SOAP

7 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

8 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

9 Windows Communication Foundation Architecture

10 Hosting WCF Side-by-Side with ASP.NET

11 WCF support the 3 state scenarios
Possibly also look for other info about these 3 scenarions on

12 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)

13 WCF data protocols WCF might also be configured to
communicate by pure XML

14 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.

15 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)]

16 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

17 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;}

18 Data transport objecter (DTO)
DataContract and DataMember When using these you might yourself include a referece to get the dll part of project


Download ppt "Distribution of functionality Webservice using WCF"

Similar presentations


Ads by Google