Wcf.docx

6
what is wcf? In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does. WCF defines four types of contracts. Service contracts Describe which operations the client can perform on the service. There are two types of Service Contracts. ServiceContract - This attribute is used to define the Interface. OperationContract - This attribute is used to define the method inside Interface. [servicecontract] interface IMycontract { [operationcontract] string MyMethod() ; } class Myservice : IMycontract { public string MyMethod () { return " hello world "; }} Data contracts Define which data types are passed to and from the service. WCF defines

Transcript of Wcf.docx

what is wcf?In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

WCF defines four types of contracts.

Service contracts

Describe which operations the client can perform on the service. There are two types of Service Contracts. ServiceContract - This attribute is used to define the Interface. OperationContract - This attribute is used to define the method inside Interface.

[servicecontract]interface IMycontract{[operationcontract]string MyMethod() ;}class Myservice : IMycontract{public string MyMethod (){return " hello world ";}}Data contracts

Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

There are two types of Data Contracts. DataContract - attribute used to define the class DataMember - attribute used to define the properties.[DataContract]class contact{ [Data Member]public string First name;[Data Member]public string Last name; }If DataMember attributes are not specified for a properties in the class, that property can't be passed to-from web service.

Fault contracts

Define which errors are raised by the service, and how the service handles and propagates errors to its clients.Message contracts

Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

EndPointWCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world.All the WCF communications are take place through end point. End point consists of three components.AddressBasically URL, specifies where this WCF service is hosted .Client will use this url to connect to the service. e.g http://localhost:8090/MyService/SimpleCalculator.svcBindingBinding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.A binding has several characteristics, including the following: Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols. Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K). Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capabilityThe following table gives some list of protocols supported by WCF binding.BindingDescription

BasicHttpBindingBasic Web service communication. No security by default

WSHttpBindingWeb services with WS-* support. Supports transactions

WSDualHttpBindingWeb services with duplex contract and transaction support

WSFederationHttpBindingWeb services with federated security. Supports transactions

MsmqIntegrationBindingCommunication directly with MSMQ applications. Supports transactions

NetMsmqBindingCommunication between WCF applications by using queuing. Supports transactions

NetNamedPipeBindingCommunication between WCF applications on same computer. Supports duplex contracts and transactions

NetPeerTcpBindingCommunication between computers across peer-to-peer services. Supports duplex contracts

NetTcpBindingCommunication between WCF applications across computers. Supports duplex contracts and transactions

ContractCollection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. Each operation is a simple exchange pattern such as one-way, duplex and request/reply.Below figure illustrate the functions of Endpoint

Example:Endpoints will be mentioned in the web.config file on the created service.