Tuesday, November 17, 2009

WCF - Basic design considerations.

Here is a list of items to consider while designing a WCF web service. These are based on many reference articles including msdn and based on my current exposure and experience to WCF.

It is important to understnad teh WCF framework and options it offers. Implemetnation is the easiest part. These may change as per your requirement.

WCF Decision Points


Security Modes:

Available Options:
• None. Turns security off.
• Transport. Uses transport security for mutual authentication and message protection.
• Message. Uses message security for mutual authentication and message protection.
• Both. Allows you to supply settings for transport and message-level security (only MSMQ supports this).
• TransportWithMessageCredential. Credentials are passed with the message and message protection and server authentication are provided by the transport layer.
• TransportCredentialOnly. Client credentials are passed with the transport layer and no message protection is applied

Recommended Options

• Message security mode, on the other hand, uses WS-Security (and other specifications) to implement transfer security. Because the message security is applied directly to the SOAP messages and is contained inside the SOAP envelopes, together with the application data, it has the advantage of being transport protocol-independent, more extensible, and ensuring end-to-end security (versus point-to-point); it has the disadvantage of being several times slower than transport security mode because it has to deal with the XML nature of the SOAP messages.
• Transport security mode uses a transport-level protocol, such as HTTPS, to achieve transfer security. Transport mode has the advantage of being widely adopted, available on many platforms, and less computationally complex. However, it has the disadvantage of securing messages only from point-to-point.

Client Credential Type

Following options are based on the type of bindings used.

Recommended Options
• Windows
• UserName
• Certificate

Recommended Protection Level: EncryptAndSign

Recommended Bindings: WsHttpBinding

There are many options available which can be configured at a later stage. Some of the recommended Bindings in addition to WsHttpBinding are given below. These can be configured as different endpoints when it is required.

- NetTcpBinding
- NetNamedPipeBinding
- NetMsmqBinding


Available Options:

- Self Hosted
- Windows Service
- IIS 5.1, 6.0, 7.0 (Depends on versions of OS)
- WAS (works only on Vista or Windows 2008)


o 6.0 on windows server 2003
 Process recycling.
 Idle shutdown.
 Process health monitoring.
 Message-based activation.
 Recycling
 HTTP only
o 7.0 or WAS on windows server 2008
 Same benefits as 5.1 and 6.0
 HTTP, TCP, Named Pipes and MSMQ
- Windows Service
o Service process lifetime controlled by the operating system, not message-activated.
o Supported by all versions of Windows.
o Secure environment.
o Supports HTTP, TCP, Named Pipes and MSMQ
o Deployment: Services must be installed with the .NET Framework Installutil.exe utility or through a custom action in an installer package.

Message Contracts

Following are some benefits of using Message Contracts instead of directly using Data Contracts.

- More controls over the SOAP Messages
- Easier to update the Operation signatures like additional parameters during before any version of WCF service is released.
- More control over how WSDL is generated.


Consider using Message Contracts based on business need.

Instance Management
Per-Call services are most preferred for scalability.

Request-Reply operations are preferred rather than call back or one way operations.

Fault contract details to be decided during design time.

Recommended transaction settings if not a distributed environment is [TransactionFlow(TransactionFlowOption.NotAllowed)]

Concurrency Management
Use default ConcurrencyMode.Single and leave thread synchronization to WCF. This is recommended along with Per-Call instantiation.
Versioning needs to be done. Details to be decided during design phase.

Use existing Logging mechanisms used in your apps or use Log4Net.

Out of the box WCF Client Proxies

Following proxies can be provided to customers for easy development
- .Net proxy
- Java proxy

Wednesday, May 13, 2009

Byte array truncation to a length of 8000 - NHibernate Mapping from binary to SqlDbType.Image in Sql server ce

There is currently an issue in saving a binaryblob to sql server ce as SqlDbType.Image. It throws the following error:

Byte array truncation to a length of 8000.

To solve this do the following:

1. Create a new driver class as shown below and override the InitializeParamenter method.

public class YourSqlServerCeDriver : SqlServerCeDriver
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
base.InitializeParameter(dbParam, name, sqlType);

if (sqlType is BinarySqlType)


PropertyInfo dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");

dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null);




2. Use this Driver type as YourSqlServerCeDriver instead of the default SqlServerCeDriver in the NHibernate Configuration.


Tuesday, May 5, 2009

How to clear Isolated Storage Cache

Find the StoreAdm.exe in their system and run the following command. may be in this folder -> C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
From command prompt -> cd C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
Storeadm /remove

Note: You can also run storeadm.exe /remove from the Visual studio command prompt


Go to C:\Documents and Settings\[user name]\Application Data\IsolatedStorage and delete all the files inside the folder “IsolatedStorage”.

Note: This will delete all the caches stored in the isolated storage for that particular user.
More details about the storeadm.ex usage:
storeadm [/list][/remove][/roaming][/quiet]

Option Description
/h[elp] Displays command syntax and options for the tool.
/list Displays all existing stores for the current user. This includes the stores for all applications or assemblies executed by this user.
/quiet Specifies quiet mode; suppresses informational output so that only error messages appear.
/remove Permanently removes all existing stores for the current user.
/roaming Selects the roaming store. Use this option with the /list or /remove options to specify that the action should apply to the roaming store.
/? Displays command syntax and options for the tool.