Download presentation
Presentation is loading. Please wait.
1
Nati Dobkin http://blogs.microsoft.co.il/blogs/ndobkin/
2
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
3
Is there such a thing OOP in WCF?
4
Use KnownTypeAttribute(type) to indicate base class what type are derived from it The type assign to this attribute have to be in driving list of the base class Person -> child -> baby All types have to be Serializable Other OOP element will not work properly
5
Use ServiceKnownTypeAttribute(type) to indicate type which is Serializable but cannot be added KnownTypeAttribute on it Use svcutil.exe to generate the data contracts Use /Refrence: option to indicate the data contracts assembly
6
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
7
Modes of Service Instances Per-call A new service instance is created and destroyed for every call Per-session (default) One service instance per client Clients cannot share instance with other clients Single All Clients share same service instance Use InstanceContextMode of ServiceBehavior Attribute to indicate it
8
WCF can maintain a private session between a client and a particular service instance. The client session has one service instance per proxy. You can enable session at contract level [ServiceContract(SessionMode = SessionMode.Required )] public interface IMyContract {…} [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class MyService : IMyContract {…} [ServiceContract(SessionMode = SessionMode.Required )] public interface IMyContract {…} [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class MyService : IMyContract {…}
9
Binding Name Session Transaction Duplex Streaming BasicHttpBindingX WsHttpBindingXXX WsDualHttpBindingXXXX NetTcpBindingXXXX NetNamedPipesBindingXXXX NetMsmqBindingX NetPeerTcpBindingX MsmqIntegrationBindingX
10
Create an instance of a proxy Close the proxy when you done
11
User the InstanceContextMode property of ServiceBehavior to indicate the instance mode The default instance mode is PerSession On client side ALWAYS close the connection to the server when you done using it
12
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
13
Client server style event handling Service Client callbackcallback We need dual channel
14
Binding Name Session Transaction Duplex Streaming BasicHttpBindingX WsHttpBindingXXX WsDualHttpBindingXXXX NetTcpBindingXXXX NetNamedPipesBindingXXXX NetMsmqBindingX NetPeerTcpBindingX MsmqIntegrationBindingX
15
Use dual channel binding Declare the callback interface Add CallbackContract property of ServiceContractAttribute to indicate the callback interface Call OperationContext.Current.GetCallbackChannel to get the callback interface Fire callback interface methods in your free time
17
Implement callback interface Creare InstanceContext and which takes the implemented callback class and send it to proxy ctor Call OperationContext.Current.GetCallbackChannel to get the callback interface
18
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
19
Server – use standard service contract Client – Implement standard Async pattern on service contract methods User AsyncPattern propertie of OperationContract Attribute to tell WCF that it is a async call
20
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
21
Binding Name Transport Encoding Interop Security Session Transaction Duplex Streaming BasicHttpBindingHTTP/SText.MTOMBP 1.1 TX WsHttpBindingHTTP/SText.MTOMWST | SXXX WsDualHttpBindingHTTP/SText.MTOMWST | SXXXX NetTcpBindingTCPBinary.NETT | SXXXX NetNamedPipeBindingIPCBinary.NETT | SXXXX NetMsmqBindingMSMQBinary.NETT | SX NetPeerTcpBindingP2PBinary.NETT | SX MsmqIntegrationBindingMSMQBinaryMSMQ TX
22
NetNamedPipeBinding: Communication between WCF applications on same computer NetMsmqBinding: Communication between WCF applications by using queuing NetPeerTcpBinding: Communication between computers across peer-to-peer services MsmqIntegrationBinding: Communication directly with MSMQ applications
24
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
25
WCF provides a rich set of features that enable to create distributed transactions in Web service application. Binding Name Session Transactio n Duplex Streaming BasicHttpBindingX WsHttpBindingXXX WsDualHttpBindingXXXX NetTcpBindingXXXX NetNamedPipesBindingXXXX NetMsmqBindingX NetPeerTcpBindingX MsmqIntegrationBindingX
26
Client Transaction Service must use client transaction Client/Service Transaction Service joins client transaction if client flows one Service is root of new transaction if no transaction was propagated Service Transaction Service performs transactional work outside scope of client transaction
27
Use TransactionFlow attribute specifies if the client transaction can flow to service Specify a transaction flow option on the contract methods that should flow a transaction [ServiceContract ] public interface IMyContract { [OperationContract] [TransactionFlow(TransactionFlowOption.Mandatory)] void MyMethod(…); }
28
Specify a transactional behavioral attribute on the methods, using TransactionScopeRequired property. public class MyService : IMyContract { [OperationBehavior(TransactionScopeRequired = true)] public string MyMethod(…) { … }
29
Create a TransactionScope (system.Transactions) Defines a region within which a transaction is active Call the service methods on the client Commit the transaction using (TransactionScope tx = new TransactionScope (TransactionScopeOption.RequiresNew)) { proxy.MyMethod(); tx.Complete(); }
30
What about OOP? Instance Management Events Asynchronies calls Advanced Bindings Transactions Extending Contract behavior Exercise
31
What do we want to achieve? An ability to interfere on contract operation invocation Dispatcher – basic unit of all data contract behaviors Located in System.ServiceModel.Dispatcher there are four of them ChannelDispatcher EndpointDispatcher DispatcherRuntime DispatcherOperation
32
A Binding AA BB Message Layer Service Model Layer (Dispatchers) ContractBehaviors CDCD EDED EDED DRDR DRDR DODO DODO DODO DODO Service Method4 Method3 Method2 Method1
34
Summary How to implement inheritance How to manage instance to server/client How to make event style architecture and async calls How to choose the right binding for your endpoint How to use transactions Dispatchers and how to extend contract behavior
35
Related Resources (You are not alone out there) WCF Blogs http://www.dasblonde.net/ http://www.idesign.net Israeli Bloggers http://weblogs.asp.net/rosherove/default.aspx http://agileisrael.org/cs/blogs/danko/ http://wortzel.blogspot.com/ http://www.lnbogen.com http://www.pashabitz.net
36
Related Resources (You are not alone out there) On my Book Shelf Programming WCF Services Microsoft® Windows® Communication Foundation Hands-on! Inside Microsoft Windows Communication Foundation Programming “Indigo”
38
Shani’s contact information Blog: http://www.human-debugger.nethttp://www.human-debugger.net E-mail: rabashani@gmail.comrabashani@gmail.com Thank you Nati’s contact information Blog: http://blogs.microsoft.co.il/blogs/ndobkinhttp://blogs.microsoft.co.il/blogs/ndobkin E-mail: ndobkin@gmail.comndobkin@gmail.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.