Service contract is a traditional C# interface. These interface are annotated with [ServiceContract] and each operation which you want to expose with [OperationContract]:
[ServiceContract] interface IHelloWorldService { [OperationContract] string GetMessage(string name); }These attributes are used for mapping between .net and SOAP for dispatching and serialization. Dispatching is the process of deciding which method to call for an incoming SOAP message. Serialization is the process of mapping between the data found in a SOAP message and the corresponding .NET objects used in the method invocation. This mapping is controlled by an operation's data contract.
WCF dispatches based on the message action which comes in the SOAP header. Each method in a service contract is automatically assigned an action value based on the service namespace and method name. Action value can be customized.
[ServiceContract(Namespace="http://hello.com/IHelloWorldService/")] interface IHelloWorldService { [OperationContract(Action="MyCustomizedActionGetMessage")] string GetMessage(string name); }
Data Contracts
Once the target method has been determined based on the action, WCF relies on the method's data contract (types used in the method signature) to perform serialization. The way WCF serializes .NET classes depends on the serialization engine in use. The default serialization engine is known as DataContract. Message is a special type in which WCF does not perform type-based serialization. Instead, it just gives you direct access to what's found in the SOAP message. With DataContract, only fields marked with DataMember will be serialized.
{DataContract]
public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } }
For more sophisticated you can always use XmlSerialize. WCF also supports serializing types marked with [Serializable].
svc file is a text file which contains the details required for WCF service to run it successfully.
With WCF, you're either writing services that expose endpoints or you're writing clients that interact with endpoints. Hence, endpoints are central to the WCF programming model and infrastructure.
(.Net Objects\Entities) (WCF Message)
Client ------------------------------> Proxy ------------------------> Messaging Layer/Channel Stack
|
| (Raw Message Data)
|
v
Service<-------------------------------Dispatcher<-------------------Messaging Layer/Channel Stack
(.Net Objects\Entities) (WCF Message)
Messaging
The messaging layer is composed of channels which processes a message. A set of channels is also known as a channel stack. There are two types of channels: transport channels and protocol channels.
Transport channels read and write messages from the network. Ex Http and Tcp
Protocol channels implement message processing protocols, often by reading or writing additional headers to the message. Examples of such protocols include WS-Security and WS-Reliability.
Client Side Service Side
Protocol Channel Protocol Channel
Protocol Channel Protocol Channel
Protocol Channel Protocol Channel
Message Encoder Message Encoder
TransportChannel------------------------------->TransportChannel
(Raw Message Data)
Proxy
The main responsibility of the proxy is to transform the caller-supplied objects (parameters) into a WCF Message object, which can then be supplied to the underlying channel stack for transmission on the wire.
Method1() Method2()
Parameter Inspection Parameter Inspection
| |
Message Formatting (serialization) Message Formatting (serialization)
| |
-----------------------------------------------------------
|
Message Inspector
Dispatcher
Operation1() Operation2()
Operation Invoker Operation Invoker
| |
Parameter Inspection Parameter Inspection
| |
Message Formatting (serialization) Message Formatting (serialization)
| |
-------------------------------------------------
|
Operation Selector
|
Message Inspector
Endpoint System.ServiceModel.ServiceEndpoint
Address System.Uri
Binding System.ServiceModel.Binding
In WCF, a binding determines how WCF is going to communicate. A binding is really the configuration that tells WCF how to build what is known as the channel stack, which is the set of objects that will work together to provide the type of communication you want for a particular endpoint.
Contract Interfaces annotated with System.ServiceModel attributes
No comments:
Post a Comment