WCF  for begineers
Upcoming SlideShare
Loading in...5

WCF for begineers






Total Views
Views on SlideShare
Embed Views



2 Embeds 310

http://debugmode.net 307
https://twitter.com 3



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    WCF  for begineers WCF for begineers Presentation Transcript

    • http://debugmode.netGetting Started with WCF Dhananjay Kumar @debug_mode
    • What definition you get on web ?Service Oriented programming model todevelop connected applicationsSDK to develop and deploy services on windowsUnifies the existing suite of .Net distributedtechnologies into a single programming model. Microsoft Innovation & Practice Team, MSCoE 2
    • Getting Started with WCFDeveloper Evangelist TelerikMicrosoft MVPMindcracker MVP@debug_modefb.com/debugmode.netDelhi User GroupC-Sharp corner User Group
    • Services and Clients Service Message Client
    • Let us startwith a Demo
    • Endpoints Client Service Endpoint Endpoint Message Endpoint
    • End Points A B C E 7
    • End Points Contracts Address Binding End Point 8
    • End PointADDRESS •WhereBINDING •HowCONTRACT •What9
    • Address (A)Every service is associated with a unique address. Location of the Service Address of the Transport Service protocol used in service 10
    • Address (A)Address specifies where the service is residing.This is an URL( Uniform Resource Locator).Address URL identifies , location of the serviceAddress should follow the Web ServiceAddressing(WS-Addressing) standard. 11
    • Address (A) WS AddressingScheme Machine Port Path 12
    • Address (A) • This is top level portion of the address. Scheme This is not as same as of protocols. • This identifies the machine name. ThisMachine can be a public URL or a local identifier • This is port number. This is an optional Port part. • This is used to locate the path. This Path gives path of the service. 13
    • Address (A) • http://localhost:8001/Dell HTTP • http://localhost/Dell • net.tcp://localhost:800/Dell TCP • net.tcp://localhost/Dell • net.msmq/private/MyService MSMQ • Net.msmq/://localhost/Dell • net.pipe://localhost/MyPipe IPC • Net.pipe://localhost.MyServicePeer network 14
    • Binding (B)Describes how a service communicates.This specifies which Protocol to be used.This specifies the encoding method to format the message content.This specifies the Security requirementsThis specifies the message exchange format.This specifies message session mode.Developer could create custom Binding also.15
    • Binding (B)Transport ProtocolMessage EncodingCommunication PatternSecurityTransaction PropertyInter Operability16
    • Binding (B) Choosing Binding No WCF Yes To WCF No Yes Disconnected Calls No Yes Legacy No Yes Cross ASMX MachineWS Basic IPC TCP MSMQ 17
    • Binding (B)Binding ClassesBinding Name as of class Transport Encoding InteroperableBasicHttpBinding HTTP/HTTPS Text,MTOM YesNetTcpBinding TCP Binary NoNetPeerBinding P2P Binary NoNetNamedPipeBinding IPC Binary NoWSHttpBinding HTTP/HTTPS Text,MTOM YesWSFederationHttpBinding HTTP/HTTPS Text,MTOM YesWSDualHttpBinding HTTP Text,MTOM YesNetMsmqBinding MSMQ Binary NoMsmqIntegrationBinding MSMQ Binary Yes18
    • Binding (B)Configuring Binding <endpoint address="Calculator" bindingSectionName="basicProfileBinding" bindingConfiguration="Binding1" contractType="ICalculator" /> <bindings> <basicProfileBinding> <binding configurationName="Binding1" hostnameComparisonMode="StrongWildcard" transferTimeout="00:10:00" maxMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" </binding> </basicProfileBinding> </bindings>19
    • Service Contract (C)A WCF Contract is a collection of OperationsAll WCF services exposes contract.This is a platform neutral and standard way to say , whatthe service will do.Defines , what a Service communicates.20
    • Contract (C)Types of Contracts Service • Describes which operation client can perform on the services.Contract • Defines which Data Type are passed to and from the services. It provides built- Data in contract for implicit type.Contract • Which error raise by service and how service propagates and handles error to its Fault client.Contract • Allow the service to interact directly with the message . Message contract canMessage be typed or un typed. This can be used for interoperability.Contract21 21
    • Contract (C) Service ContractA Service Contract reflects specific businessDescribe which operations client canperformMaps CLR types to WSDL 22
    • Contract (C) Service ContractInterfaces are used to explicitly define a ContractClasses may also be used to define a Contract.[ServiceContract] attribute is being used byinterface/class to qualify them as a contract.ServiceContract are implicitly public. 23
    • Contract (C)Service Contract // Define a service contract. [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] public interface IDataContractCalculator { [OperationContract] ComplexNumber Add(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Multiply(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Divide(ComplexNumber n1, ComplexNumber n2); }24
    • Contract (C)Data ContractThese are the contractual agreement about the formatand structure of the payload data in message exchangebetween a service and its consumer.Defines which Data types are passed to and from theservice.Its specifies CLR type to XML schema.25
    • Contract (C) Data ContractDataContract are preferred WCF way to enableSerialization.WCF defines implicit contract for built in types like int andstring.Developer has to explicitly expose complex types as DataContract.[DataContract] and [DataMember] attribute are used todefine a type as Data Contract. 26
    • Contract (C)Data Contract [DataContract] public class ComplexNumber { [DataMember] public double Real = 0.0D; [DataMember] public double Imaginary = 0.0D; }27
    • Contract (C) Message ContractIt gives control over SOAP message structure on both header and bodycontent.Developer can designate optional SOAP headers.It provides additional control over the WSDL generation.It is used to interoperate with another non- WCF service.It is used to control security issue at level of message. 28
    • Contract (C) Fault ContractThis translates .Net Exception to SOAP fault propagated to consumerThis can be applied to operation only.This is not Inheritable.This can be applied multiple times.This enables developer to declare which faults a given service operationmight issue if things goes wrong. 29
    • Creating End PointCould be created declaratively in configuration file.Could be created imperatively through code.Any thing done through code can be done with configuration file andvice versa.It is considered good practice to use configuration file to specify Endpoints. This accommodates changes without recompiling the code. 30
    • Defining Endpoints<?xml version="1.0" encoding="utf-8" ?><configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.serviceModel> <services> <service serviceType="CalculatorService"> <endpoint address="Calculator" bindingSectionName="basicProfileBinding" contractType="ICalculator" /> </service> </services> </system.serviceModel></configuration>
    • Multiple End PointFor service exposed to multiple clients ; it makes sense tospecify more than one End point.This enables client to use the endpoint that is mostapplicable for them.When creating multiple endpoints each client must haveunique addressIf two client uses the same address , error will raise atservice load time. 32
    • Multiple End Point• <endpoint address="http://localhost:8890/a" binding="wsHttpBinding" contract="HotsingSamples.IService1"/>• <endpoint address="http://localhost:8000/b" binding="basicHttpBinding" contract="HotsingSamples.IService1"/>• <endpoint address="net.tcp://localhost:8001/c" binding="netTcpBinding" contract="HotsingSamples.IService1"/>33
    • HostingWCF services can not exist in void.It must be hosted.WCF services are hosted in windows process called hostprocess.A single host process can host multiple service.A same service can be hosted in multiple host process. 34
    • WCF basic task cycle 1. Defining Service Contract 2. 5. Impleme Building nting Clients Service Contract 3. 4. Configuri Hosting ng Services Services 35
    • DEBUG_MODE http://debugmode.net Dhananjay Kumar