What? -> Windows communication foundation, it is a framework to build SOA (services-oriented architecture)
Why? -> not only http protocols
Base? Service Contract and Data Contract
.svc -> service view controller
Inside interface:
ServiceContract -> interface, list methods, always use [OperationContract]
OperationContract -> method name
DataContract -> class name , always use [DataMember]
App.config
default binding -> BasicHttpBinding
wcf service library -> is not hosting any wcf service
How to consume WCF? -> you will use the ChannelFactory
System.ServiceModel passing the EndpointAddress
-> every consumption, should have a channel. If you have 2
WCF, you need to create 2 channels
app.config:
Edit WCFConfiguration
Difference bewteen app.config server from the winforms projects, it is under the (the other is )
to create a channel, you pass the endpoint, or the endpoint name
how to create a windows Service project
Start a service host:
ServiceHost host = null
**How to install a service**?
right click on service -> add installer
how to go to root folder in cmd? cd \
how to go to a target folder in cmd? cd "target folder"
how to install windows service exe? -> use the installutil
svc -> you can service reference if you have that file. otherwise you cannot
address="mex" contract="IMetadataExchange"
-> ServiceReference on selfapplications
-> also add behaviour (behaviourConfiguration)
client:
for service reference, you can have the proxy
proxy = new MathServiceClient("nameService")
was -> windows process active services
run execute -> inetmgr (iis manager)
How to make OneWay Message Exchange Pattern -> (IsOneWay = true) -> fire and forget
Duplex Message Pattern -> **basicHttpBinding** to **wsDualHttpBinding**
httpBasicBinding -> wsDualHttpBinding
[ServiceContract(CallbackContract = typeof(IMathServiceCallback))]
**How to implement callback**? You need to implement the interface in the interfaceService
when you have call back you need to create the InstanceContext passing the callback as parameter
and then you can create the proxy again. omg
Exception Handling
why not use try catch -> should not throw .net CLR Exceptions, it could be consumed by another system.
to show the error message display:
serviceBehavior>
**IsOneWay** methods never throw errors. You always need to be careful.
**How to implement errors**? Using Fault Exceptions -> FaultCode
[FaultContract(typeof(DivisionFault))]
throw new FaultException(objecCreated);
basicHttpBinding != wsHtpBinding (supports session)
[ServiceBehavior(InstanceContextMode= InstanceContextMode.PerSession)]
PerSession = default
PerCall -> no data session
Single -> uhhh, for everyclient
How to use Transaction?
[(TransactionsFlow(TransactionFlowOption.Mandatory)]
[ServiceBehavior(TransactionIsolationLevel = System.Transactios.IsolationLevel.Serializable)]
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
1- First the operation needs to be mandatory
2- the interface implamated needs to have the scope required
3- the service needs to be serializable
transaction can not use basicHttpBinding.
you use the wsHttpBinding
**How to implement Transactions?** Always use the TransactionScope ,
transaction has locked the database, that is amazing omg
session support for transactions ->
1- Interface: ServicesContract(SessionMode = SessionMode.Required).
2- Session of transactions is just a local variable. interesting
Service
3- Service: ServiceBehavior ->
InstanceContextMode = InstanceContextMode.PerSession, TransactionAutoCompleteOnSessionClose = true : productService
TransactionAutoComplete = false : operation
To show the ThreadID we just need to use -> Thread.CurrentThread.ManagedThreadId.ToString());
self hosting applications -> you create a console and then you create the Host object. after you need to specify it on the config apps the mex
when you refer the self hosting application you need to to add a service, but yo uneed the different URL, and add there. you first need to start the selfhost application, and then you try to add the service, and MANUALLY
you need to add the Address, then you will have the go. The default address is not the right one.
To implement concurrency -> ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)
everytime you call a wcf method you have a new thread. (My quesiton is, that happens in normal c# as well?, we need to try)
Course link
What? -> Windows communication foundation, it is a framework to build SOA (services-oriented architecture) Why? -> not only http protocols Base? Service Contract and Data Contract .svc -> service view controller
Inside interface: ServiceContract -> interface, list methods, always use [OperationContract] OperationContract -> method name DataContract -> class name , always use [DataMember]
App.config default binding -> BasicHttpBinding
wcf service library -> is not hosting any wcf service
AddReference -> wcf dll + system.serviceModel. + system.RunTime.Serialization + System.Service.Web
Bindings: BasicHttpBinding(); -> taking help of IIS (application level) NetTcpBinding(); -> who uses NetTcp? (transport level) wsDualHttpBinding (Supports session)
Start multiple projects -> solution properties, startup -> select multiple projects
How to consume WCF? -> you will use the ChannelFactory System.ServiceModel passing the EndpointAddress -> every consumption, should have a channel. If you have 2 WCF, you need to create 2 channels
app.config: