Sunday, December 26, 2010

Introduction to Silverlight 4

I've Created a good presentation to introduce the new Microsoft Silverlight 4 Technology.

Hope it's really useful for all of you;
You can share it with your friends if you need :)

For More Info Please Visit: Silverlight Official Web Site

Saturday, October 16, 2010

Transactions in WCF: (WCF Part 11)


The most important part to understand from my opinion when working with WCF is the transaction part.
A transaction treats a group of operations as an atomic unit, so either all succeed or all fail.

WCF supports two types of transactions: shared transactions and transacted messaging.

WCF supports two transaction protocols:

  1. OleTransaction protocol: Used for transaction control between WCF applications.
  2. WS-AtomicTransaction protocol: Enables WCF applications to flow transactions to interoperable applications, such as Web services that have been built by using third-party technology.

Transaction Process (Client & Server Side)

1-Client Side
Clients use a TransactionScope object to group operations into transactions:



using (TransactionScope sc = new TransactionScope())







As well as specifying transaction requirements, the client can control the isolation level and timeout for the transaction by using a TransactionOptions object:



TransactionOptions top = new TransactionOptions();

    top.IsolationLevel = IsolationLevel.ReadCommitted;

    using (TransactionScope sc = new TransactionScope(TransactionScopeOption.RequiresNew, top)) //...


2-Server Side

The ServiceBehavior attribute enables you to configure the service as a whole for transaction time-outs, isolation level, and whether transactions complete when a session closes.
The OperationBehavior attribute helps you to control whether a transaction is required for an operation, and whether transactions complete if no exception is thrown.

WCF can use Microsoft Message Queuing, or MSMQ, to pass messages between clients and services. Queuing can improve application resilience and scalability.

Reliable Sessions in WCF:

A reliable session provides session-based delivery for WCF messages, regardless of the number or type of transport intermediaries between two endpoints.

Reliable sessions handle lost or duplicated messages. Messages are delivered exactly once, and can optionally be delivered in order. If a message cannot be delivered, the sender is informed.

They are enabled by default for theWsDualHttp, NetNamedPipeandMsmqIntegrationbindings, and can be enabled for theNetTcp, WsHttpandWsHttpFederationbindings.


Finally, I’d like to thank all of you for your Attention and hope that you’ve learned something new from these WCF 11 parts that I’ve written :)

Mohamed Adel Mahmoud.
Microsoft Intern – Senior Microsoft Student Partner – Microsoft Egypt.
  For More Info Please Visit: WCF Resources Page  

Security Features of WCF: (WCF Part 10)


This Time I’ll be focusing more on the Security Part in WCF.

WCF provides comprehensive security features in three main areas: transfer security, authentication and authorization of clients, and auditing.


Security Modes of WCF:

WCF can provide authentication, privacy, and integrity for messages by using two mechanisms:

  1. Transport mode: which uses the security features of a transport layer such as HTTPS. This mode has performance benefits due to the optimized nature of the underlying protocols, but it has a restricted set of credential or claim types. This mode also only works between two transport endpoints.
  2. Message mode: which protects the message itself by using a protocol such as WS-Security.

You can specify the security for a binding by setting its SecurityMode property. By default, the BasicHttpBinding has no security configured. Other HTTP bindings use WS-Security, and TCP and Named Pipe bindings use Windows security.

You can use the .NET PrincipalPermission attribute to restrict access to an operation based on name, role, or authentication status.


  For More Info Please Visit: WCF Resources Page  

Guidelines for Configuring the Transport Layer: (WCF Part 9)


NATs and Firewalls:
Firewalls and Network Address Translators (NATs) may make it impossible to use duplex contracts, since NATs hide IP addresses. Firewalls commonly restrict the protocols and ports that can be used, and this may restrict services to using HTTP or HTTPS as a transport.

Streaming Message Transfer:
By default, entire messages are buffered in memory by WCF transports. However, you can eliminate the need for large memory buffers by exposing the message body as a stream.

Unidirectional or bidirectional streaming is enabled through the TransferMode property of the transport binding element.

Note that there are some restrictions on the use of streaming, especially when using certain WCF features, such as reliable messaging, transactions, and SOAP security, which may require buffering.

Transport Quotas:
Transport quotas should be used to ensure that connections do not consume excessive resources.

WCF supports two main types of quota: timeouts to guard against denial of service attacks and allocation limits to guard against excessive memory use.

  For More Info Please Visit: WCF Resources Page  

Binding in WCF: (WCF Part 8)


Choosing a Predefined Binding in WCF:
WCF has nine built-in bindings.e.g.(
NetTcpBinding and other Built-in Bindings )

Defining a Custom Binding in WCF:

A binding is made up of a collection of binding elements, each of which describes some feature of the endpoint's communication. It is important to know about transports, encoding, and other elements when you create a custom binding, because you must choose which elements to put into the stack. A binding must specify at least a transport and an encoder. For example, the NetTcpBinding combines the TCP transport with a binary encoder.

You may wish to create a new binding to accommodate a new transport or encoding.

WCF provides three predefined transports:

  1. HTTP: Used for Web service communication.
    You would choose HTTP if you want to do one of the following:
    1. Host services in IIS 6.0 or later.
    2. Communicate across machines.
    3. Provide good tool support for development, diagnosis, and other activities.
  2. TCP: Typically used for binary communication across computers.
    You would choose TCP if you want to do one of the following:
    1. Provide minimal latency and maximal throughput.
    2. Communicate across computers.
  3. Named Pipes: Provide efficient communication between applications on the same computer.
    You would choose Named Pipes if you want the most efficient communication on a single computer.

In addition to a transport, a binding requires a message encoder to serialize a WCF message into bytes.

WCF has three encoders to handle text, binary, and MTOM data. The text encoder supports plain old XML (POX) as well as SOAP encoding. If your encoding requirement is not handled by these three encoders, you can write your own custom encoder.

  For More Info Please Visit: WCF Resources Page  

Asynchronous Invocation in WCF (WCF Part 7)


The client calls the Begin operation by passing any required parameters, a callback function, and a state object. The callback function is called when the operation finishes.

object can be any object you want to pass to the callback function and in WCF it is usually a reference to the proxy:


IAsyncResult iar = proxy.BeginAdd(i1, i2, MyCallback, proxy);

/*This function returns immediately and provides an IAsyncResult that the caller can use to check the state of the operation.*/



The callback function is executed when the service operation completes, and the callback function calls the matching End method:



static void MyCallback(IAsyncResult iar)


   double val = ((AddProxy)iar.AsyncState).EndAdd(iar);




WCF Service Behavior:

it's very necessary to demonstrate how the clients will connect with the WCF Services (e.g. How many service instances will be used to serve the clients, operation counts, Error handling, Security, such as impersonation, authorization, Metadata   etc)

Behaviors may be code-only, or may also use configuration settings. e.g.



/*This line of code will make all the clients using the same instance of the service.*/


OR you can use Throttling:

Throttling allows you to set limits on access to a service, such as the number of connections or pending calls.

You configure throttling in the configuration file:


<throttling maxConcurrentCalls = "12" maxConnections = "34" maxInstances = "56" />


Developers can also retrieve the throttling settings at runtime, and modify them before opening the service.

Developers can create custom behaviors by using IServiceBehavior and IEndpointBehavior.
  For More Info Please Visit: WCF Resources Page  

Monday, September 20, 2010

Fundamentals of Creating a WCF Client (WCF Part 6)


Fundamentals of Creating a WCF Client: Like almost all other distributed technologies, clients use proxies to access WCF services.

    Proxies can be created in one of two ways:

  1. at design time by using the svcutil.exe command line tool
  2. dynamically at runtime by using a ChannelFactory.

A ChannelFactory provides a flexible way to create proxies at runtime, by creating a factory from the address, binding details, and contract details, and then calling CreateChannel on the factory.

Creating a Client by Using a Channel Factory:


ChannelFactorycf = new ChannelFactory(new EndpointAddress("http://localhost/MyService/EndPoint1"),new BasicHttpBinding());
IMyChannel ch1=cf.CreateChannel();


To send messages you must open the channel. and after finishing you have to Close the channel.

The ChannelFactory class has a number of methods and properties that enable you to access features of the underlying channel. e.g the Credentials property:


proxy.ChannelFactory.Credentials.UserNamePassword.UserName = "Mohamed Adel Mahmoud";
proxy.ChannelFactory.Credentials.UserNamePassword.Password = “P@$$w0rd”;


  For More Info Please Visit: WCF Resources Page  

Sunday, September 19, 2010

WCF Hosting Options: (WCF Part 5)


Options for Hosting a WCF Service:

  1. Internet Information Server (IIS): WCF services can be hosted within Internet Information Services, which provides a number of advantages if the service uses HTTP as its transport protocol.

  2. Windows Activation Service: is the new process activation mechanism that is a feature of IIS 7.0. IIS 7.0 is a part of Microsoft Windows Vista and the newly released Microsoft Windows Server 2008.

  3. Self Hostd:WCF services can be hosted inside any .NET managed application, such as console applications and Windows Forms or Windows Presentation Foundation (WPF) graphical applications.


    ServiceHost myHost = new ServiceHost(typeof(MyService), baseAddress);
    myHost.Open(); //to start the service


  4. Managed Windows Service:A WCF service can be registered as a Windows Service, so that it is under control of the Windows Service Control Manager (SCM).

    This is suitable for long-running WCF services that are hosted outside of IIS in a secure environment and are not message- activated.

    To host a WCF service in this way, the application must be written as a Managed Windows Service by inheriting from System.ServiceProcess.ServiceBase

    It must also implement a WCF service contract interface and then create and open a ServiceHost to manage the WCF service.

  For More Info Please Visit: WCF Resources Page  

WCF Integration with MSMQ and COM+: (WCF Part 4)


WCF can act as the client or server to existing MSMQ applications. Using the MSMQ integration channel, WCF clients and services can exchange classic MSMQ messages with MSMQ applications.

Existing component-based application logic hosted in COM+ can be exposed as Web services. Each exposed COM class will be represented by a service, the contract for which is derived directly from the component's interface definition. The COM+ Service Model Configuration tool (ComSvcConfig.exe) is used to create Web services to represent COM interfaces.

  For More Info Please Visit: WCF Resources Page  

WCF Features (WCF Part 3)


WCF has many features like :

  1. WCF provides one model for writing distributed applications not as many models like before (COM+, MSMQ, etc)
  2. WCF Reduced the code
  3. WCF provides a comprehensive set of logging and tracing features

WCF Message Exchange Patterns:

WCF supports three message exchange patterns:

  1. In one-way messaging, also known as simplex messaging: a client sends a message to a service without expecting a response.

  2. In request-response messaging: a client sends a message to a service, and waits for a reply.

  3. In duplex messaging, the client and service communicate freely with each other without the synchronization that request- response messaging requires. Duplex messaging is used to implement asynchronous communication.

  For More Info Please Visit: WCF Resources Page  

Tools Provided by WCF. (WCF Part 2)


WCF provides a number of tools that make it easier to create, deploy, and administer WCF applications:

  1. COM+ Service Model Configuration Tool (ComSvcConfig.exe):provides a representation of the service contracts and bindings for WCF Web services that is both strongly typed and COM-visible, and enables developers of COM+ applications to expose one or more interfaces on a COM+ component as Web services.
  2. Configuration Editor (SvcConfigEditor.exe):Enables administrators and developers to create and modify configuration settings for WCF services by using a GUI.
  3. Find Private Key Tool (FindPrivateKey.exe):Retrieves a private key from a key store.
  4. ServiceModel Metadata Utility (svcutil.exe):Generates service model code from metadata, and metadata from service model code. Most often used to generate client-side proxies to WCF services.
  5. ServiceModel Registration Tool (ServiceModelReg.exe):Manages the registration of the WCF ServiceModel with Internet Information Services on a single computer. It can be used to register, unregister, and re- register WCF.
  6. TraceViewer Tool (SvcTraceViewer.exe):Enables developers and administrators to view, group, and filter trace messages that relate to WCF services.
  7. WS-AtomicTransaction Configuration Utility (wsatConfig.exe):Configures WS- AtomicTransaction support settings, such as ports, certificates, and accounts.
  For More Info Please Visit: WCF Resources Page  

Introduction to Windows Communication Foundation (WCF)


The Microsoft .Net FrameWork 3.5 consists of the .NET Framework version 2.0 components as well as 4 developer-focused innovative technologies:

  1. Windows Presentation Foundation (WPF)
  2. Windows Communication Foundation (WCF)
  3. Windows Workflow Foundation (WF)
  4. Windows CardSpace (CardSpace).

WCF services expose endpoints that clients and services use to exchange messages. Each endpoint consists of an 1- address, 2-a binding, and 3- a contract.

  1. The address identifies where the service is located on the network.
  2. The binding defines how the client needs to communicate with the service.(Security wise)
  3. The contract defines what the service can do.

  For More Info Please Visit: WCF Resources Page  

Saturday, August 14, 2010

Writing Data from a database to an XML Document


Using XML and ADO.NET mode, reading a database and writing to an XML document and vice versa is not a big deal. In this section of this article, you will see how to read a database table's data and write the contents to an XML document.

The DataSet class provides method to read a relational database table and write this table to an XML file. You use Write Xml method to write a dataset data to an XML file. 

In this sample example, I have used commonly used Northwind database comes with Office 2000 and later versions. You can use any database you want. Only thing you need to do is just chapter the connection string and SELECT SQ L query.

In this sample, I reate a data adapter object and selects all records of Customers table. After that I can fill method to fill a dataset from the data adapter.


In this sample example, I have used OldDb data provides. You need to add reference to the Syste.Data.OldDb namespace to use OldDb data adapters in your program. As you can see: first I create a connection with northwind database using OldDbConnection. After that I create a data adapter object by passing a SELECT SQL query and connection. Once you have a data adapter, you can fill a dataset object using Fill method of the data adapter. Then you can WriteXml method of DataSet, which creates an XML document and write its contents to the XML document. In our sample, we read Customers table records and write DataSet contents to OutputXml.Xml file in C:\ dir.

using System;

using System.Xml;

using System.Data;

using System.Data.OleDb;

namespace ReadingXML2


class Class1


static void Main(string[] args)


// create a connection

OleDbConnection con = new OleDbConnection();

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb";

// create a data adapter

OleDbDataAdapter da = new OleDbDataAdapter("Select * from Customers", con);

// create a new dataset

DataSet ds = new DataSet();

// fill dataset

da.Fill(ds, "Customers");

// write dataset contents to an xml file by calling WriteXml method





For more information please Visit:

Tuesday, June 22, 2010

ASP.NET MVC for Web Form Programmers

Are you comfortable creating ASP.NET Web Form applications but even a little curious about what all the fuss is about MVC and test-driven development? In this session, Web Form junkie Paul Litwin takes a critical look at the world of ASP.NET MVC, but not from any expert point of view. Instead, Paul shares his experience as a Web Form developer who decided to take a closer look at this radical new approach to ASP.NET development. Come hear what Paul learned and if he plans to employ ASP.NET MVC in his future ASP.NET applications.

Get Microsoft Silverlight

For more information please Visit:

MVC Official Web Site

Monday, June 14, 2010

Windows Phone 7 to add Flash 10.1 support?

Flash Player 10.1 prevents out-of-memory browser crashes by shutting down instances where a SWF file attempts to allocate more memory than is available on the device.

Search This Blog