WCF Binding Comparison

Oct 29, 2010 Posted by Lara Kannan 0 comments
WCF Binding Comparison

In my ongoing quest to produce the simplest table possible summarizing the key differences between the various Windows Communication Foundation (WCF) built-in bindings, I came up with the following:









Binding Class Name TransportMessage EncodingMessage VersionSecurity Mode
BasicHttpBindingHTTPTextSOAP 1.1None
WSHttpBindingHTTPTextSOAP 1.2 & WS-A 1.0Message
WSDualHttpBindingHTTPTextSOAP 1.2 & WS-A 1.0Message
WSFederationHttpBindingHTTPTextSOAP 1.2 & WS-A 1.0Message
NetTcpBindingTCPBinarySOAP 1.2Transport
NetPeerTcpBindingP2PBinarySOAP 1.2Transport
NetNamedPipesBindingNamed PipesBinarySOAP 1.2Transport
NetMsmqBindingMSMQBinarySOAP 1.2Message
MsmqIntegrationBindingMSMQX**Not SupportedTransport


Share

Types of Services in WCF

Posted by Lara Kannan 2 comments

There are three types of services in WCF, and they are the following:
  • Typed
  • Untyped
  • Typed message
Typed Service

A typed service is the simplest of services, and is very similar to the methods in a class, in that both the parameters and method return values can be both simple or complex data types.

A typed service can also return a value or return a modified parameter value. The following example illustrates a typed service in which typed operations are used:

[ServiceContract(SessionMode = SessionMode.Required)]
public interface IBookOrder
{

[OperationContract]
void PlaceOrder(string title, decimal cost);

}

This next example shows the use of the ref parameter to return a modified parameter value:

[ServiceContract(SessionMode = SessionMode.Required)]
public interface IBookOrder
{

[OperationContract]
void PlaceOrder(string title, decimal cost, ref ordernumber);

}

Data contracts provide the ability to extend this functionality and accept complex data types as parameters or returned results.

Typed Message Service

A typed message service accepts and returns message information via custom classes that are defined by message contracts. With a typed message service the operation accepts a custom message parameter in the form of a message class, and the responsibility of deciphering the message falls upon the service operation.

The following example shows a service contract along with a defined typed message that is used as a parameter in a typed service operation:

[ServiceContract]
public interface IBookOrder
{

[OperationContract]
void PlaceOrder(Contract MyContract);

}

[MessageContract]
public class MyContract
{

[MessageHeader]
string Title;

[MessageBodyMember]
decimal cost;

}

Untyped Service

Untyped services let you do your work at message level, so this is the most complex of the service types. At this level the service operation accepts and returns message objects so it is recommended that you use this type of service only when you need this level of control, that is, working directly with the message.

The following example shows an operation contract passing a message object as an untyped service operation:

[ServiceContract(SessionMode = SessionMode.Required)]
public interface IBookOrder
{

[OperationContract]
void PlaceOrder(message IncomingMessage);

}

Thanks : codesubmit.com

Share

WCF Service Bindings - Basic

Posted by Lara Kannan 0 comments
Windows Communication Foundation Bindings

This article offers a brief explanation on the basic concepts of the Communication part in the Windows Communication Foundation - WCF. In order to communicate with a WCF service, the client needs to know simple details like 'ABC' of the service.

Whats meant by ABC of WCF ?
Before we learn the ABC of WCF, we need to know how a WCF service is made accessible to the clients.

A WCF service allows communication through an Endpoint. And the endpoint is the only point of communication of the WCF service that enables message exchange with the client as shown in below figure.


And this Endpoint needs to set the ABC attributes of the WCF service as shown in the below figure.


Thus in the WCF world, ABC is an abbreviation of Address, Binding and Contract attributes of an Endpoint.

An example of the Endpoint

Let us quickly run through an example of an endpoint setting in the web.config file at the service side.
<endpoint 
address="http://localhost:8731/EmpWCFService.ServiceImpl.Manager/"
binding="basicHttpBinding"
contract="EmpWCFService.ServiceContract.IEmployee" />

Where,
- address is the network address of the service,
- binding specifies transport protocol (HTTP, TCP, etc.) selected for the service &
- contract is the interface the service implements.

So, what is the Binding?

The Binding is an attribute of an endpoint and it lets you configure transport protocol, encoding and security requirements as shown in the below figure.



Types of Binding

WCF supports nine types of bindings. WCF allows you to transmit messages using different transport protocols (such as HTTP, TCP, and MSMQ) and using different XML representations (such as text, binary, or MTOM).

  1. Basic binding - BasicHttpBinding
    • It is suitable for communicating with ASP.NET Web services (ASMX)-based services that comfort with WS-Basic Profile conformant Web services.
    • This binding uses HTTP as the transport and text/XML as the default message encoding.
    • Security is disabled by default
    • This binding does not support WS-* functionalities like WS- Addressing, WS-Security, WS-ReliableMessaging
    • It is fairly weak on interoperability.
  2. Web Service (WS) binding - WSHttpBinding
    • Defines a secure, reliable, interoperable binding suitable for non-duplex service contracts.
    • It offers lot more functionality in the area of interoperability.
    • It supports WS-* functionality and distributed transactions with reliable and secure sessions using SOAP security.
    • It uses HTTP and HTTPS transport for communication.
    • Reliable sessions are disabled by default.
  3. TCP binding - NetTcpBinding
    • This binding provides secure and reliable binding environment for .Net to .Net cross machine communication.
    • By default it creates communication stack using WS-ReliableMessaging protocol for reliability, TCP for message delivery and windows security for message and authentication at run time.
    • It uses TCP protocol and provides support for security, transaction and reliability.
  4. MSMQ binding - NetMsmqBinding
    • This binding provides secure and reliable queued communication for cross-machine environment.
    • Queuing is provided by using MSMQ as transport.
    • It enables for disconnected operations, failure isolation and load leveling
  5. Peer network binding - NetPeerTcpBinding
    • This binding provides secure binding for peer-to-peer environment and network applications.
    • It uses TCP protocol for communication
    • It provides full support for SOAP security, transaction and reliability.
  6. Duplex WS binding - WSDualHttpBinding
    • This binding is same as that of WSHttpBinding, except it supports duplex service.
    • Duplex service is a service which uses duplex message pattern, which allows service to communicate with client via callback.
    • In WSDualHttpBinding reliable sessions are enabled by default. It also supports communication via SOAP intermediaries.
  7. IPC binding
    • Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.
  8. Federated WS binding
    • Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.
  9. MSMQ integration binding
    • Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.
That's all at this moment. Will see more in the next post.

Thanks : wcftutorial.net & c-sharpcorner.com

Share

To Upper Case First Letter of a String in C#

Oct 28, 2010 Posted by Lara Kannan 0 comments
Utilize a simple extension method to capitalize the first letter of a string.


public class Program
{
static void Main(string[] args)
{
string s = "toUpperFirstLetter";

// ToUpperFirstLetter is the extension method defined below
Console.WriteLine(s.ToUpperFirstLetter());

// output: ToUpperFirstLetter
Console.ReadLine();
}
}

// string extension class
public static class StringExtension
{
// string extension method ToUpperFirstLetter
public static string ToUpperFirstLetter(this string source)
{
if (string.IsNullOrEmpty(source))
return string.Empty;
// convert to char array of the string
char[] letters = source.ToCharArray();

// upper case the first char
letters[0] = char.ToUpper(letters[0]);

// return the array made of the new char array
return new string(letters);
}
}


Source : www.codemeit.com
Share
Labels: ,