Moustafa Refaat
Login   Search
Skip Navigation Links
Home
Publications
Service Offerings
Downloads and Samples
My Resume
Endorsements
Contact Me
Books
Technical Articles
Software Packages
Scroll up
Scroll down
BizTalk The Practical Course
Mastering The BizTalk Technical Interview
Soduku:Challenging Puzzels
Scroll up
Scroll down
Design Patterns Review
Software Architecture Basics Review
Simplified BizTalk Content Based Routing for a Pass_Throu data
An Extensible Light Xml Rules Engine Component
Secure Messaging Solution
Create a SQL Database Programmatically
BizTalk Unzip Adapter
Implementing Singleton pattern with BizTalk Orchestrations
Developing BizTalk Custom Adapters
The BizTalk ESB Toolkit 2.0 experience Series
Scroll up
Scroll down
Setting the ESB Toolkit on the 64 Bit Machines
How The ESB Works
Sample Custom Resolver
Scroll up
Scroll down
Recent Training
Scroll up
Scroll down

News List

  • Toronto Code Camp Presentation is uploaded
  • BizTalk: The Practical Course is recommended by Micorsoft
  • Canadian Gigs Network (www.CanadianGigs.Net) a job web site focusing on Canadian Jobs
  • BizTalk Technical Interview Preparation
  • GT-DataSafe© Online Backup for Amazon Storage Services 3.0 is released
  • Soduku Challenging Puzzles
  • BizTalk: The Practical Course
  • Mastering The BizTalk Technical Interview is Published.

Technical Articles

  • SharePoint List Simplified Configuration Store
  • WCF and xsd:choice how to implement!
  • WCF: Refactoring a Plain old XML web service to a WCF Service
  • Setting the ESB Toolkit on the 64 Bit Machines
  • The BizTalk ESB Toolkit 2.0 experience Series
Skip Navigation Links>Home

 Welcome to my website, in the following pages you will find information about my experience, publications, software products I developed, and synopsis of the services I provide in the areas of software development, design, and architecture. As a software consultant, I worked on different roles, such as BizTalk Developer, SharePoint Developer, BizTalk Architect, Enterprise Architect, Technical Lead, and Instructor. I mainly provide services in the  GTA (Toronto, ON) , though I have provided services in Calgary AB, St Johns NFLD, Chicago IL, and Denver CL in the past. I work with many technologies but I am mainly focused on Microsoft .Net platform. Some of the technologies that I specialize in are:

  • BizTalk
  • SharePoint
  • ASP.Net
  • .Net 3.5
  • Amazon Web Services
  • Oracle
  • MS Dynamics CRM and GP

Lately I have been focusing on the cloud with Azure and Amazon web services.  Feel free to contact me at Moustafa@MoustafaRefaat.com if you have any questions regarding any of my posts, books, services, or products.

DateNews
07/05/2010Toronto Code Camp Presentation is uploaded
11/12/2009BizTalk: The Practical Course is recommended by Micorsoft
10/09/2009Canadian Gigs Network (www.CanadianGigs.Net) a job web site focusing on Canadian Jobs
07/08/2009BizTalk Technical Interview Preparation
11/07/2009GT-DataSafe© Online Backup for Amazon Storage Services 3.0 is released
06/04/2009Soduku Challenging Puzzles
06/04/2009BizTalk: The Practical Course
17/03/2008Mastering The BizTalk Technical Interview is Published.

06/04/2009

Soduku Challenging Puzzles

Rss
<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
SharePoint List Simplified Configuration Store

This is a sample configuration store that I wrote for a SharePoint implementation that I was working on. The configuration manager has a simple interface that takes two keys (siteID, and Key)  and returns the string associated with these keys here is the interface definition

 

public interface IConfigurationManager

    {

        string GetConfiguration(string siteID, string key);

    }

 

The implementation for the IConfiguration manager expects to find the list URL and the site URL where the list exists(the list can exist in any site) in the application settings of the web.config. The implementation caches the retrieved values which has its own draw backs as changes to the list are not reflected till the cash expires but for this implementation the requirement did not expect lots of changes.

/// <summary>

    ///  Reads the configuration information from the Configuration list

    ///  the URL for the list is stored in application settings in key

    ///   <add key="ConfigListURL" value="/Configuration/Lists/ConfigurationStore" />

    ////  <add key="configWebSiteURLKey"  value="http://localhost/Configuration"/>

    /// 

    /// </summary>

    public class ConfigurationManager: IConfigurationManager

    {

        private const string configListNameKey = "ConfigListURL";

        private const string configWebSiteURLKey = "configWebSiteURLKey";

       

        public ConfigurationManager()

        {

        }

        public string GetConfiguration(string siteID, string key)

        {

            string entry = null;

            bool dirty = false;

            Dictionary<string, Dictionary<string, string>> globalMap = GetMap();

            Dictionary<string, string> siteMap = null;

            if(globalMap.ContainsKey(siteID))

            {

                siteMap = globalMap[siteID];

                if(siteMap.ContainsKey(key))

                {

                entry = siteMap[key];

                }

                if(null == entry)

                {

                    dirty = true;

                    entry = GetConfigEnrtyFromSharePoint(siteID, key);

                    if (entry != null)

                    {

                        siteMap[key] = entry;

                    }

                }

            }

            else

            {

                dirty = true;

                entry = GetConfigEnrtyFromSharePoint(siteID, key);

                siteMap = new Dictionary<string, string>();

                if (entry != null)

                {

                    siteMap[key] = entry;

                }

                globalMap[siteID] = siteMap;

            }

            // update map if need be

            if (dirty)

            {

                HttpContext.Current.Cache[globalMapCacheKey] = globalMap;

            }

            return entry;

        }

        private string GetValue(SPListItem item)

        {

            string value = string.Empty;

            try

            {

                value = item["Value"].ToString();

            

            }

            catch

            {

                Debug.WriteLine("NoValue");

            }

            return value;

        }

 

        const string queryformatstr = "<Where> <And><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq><Eq><FieldRef Name='SiteID'/><Value Type='Text'>{1}</Value></Eq> </And></Where>";

        private string GetConfigEnrtyFromSharePoint(string siteID, string key)

        {

            string result = null;

            string SiteUrl = WebConfigurationManager.AppSettings[configWebSiteURLKey];

            SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite siteCollection = new SPSite(SiteUrl))

                {

 

                    using (SPWeb rootweb = siteCollection.OpenWeb())

                    {

 

                        string configlistUrl = WebConfigurationManager.AppSettings[configListNameKey];

                        SPList list = null;

                        try

                        {

                            list = rootweb.GetList(configlistUrl);

                            SPQuery oQuery = new SPQuery();

                            oQuery.Query = string.Format(queryformatstr, key, siteID);

                            SPListItemCollection collListItems = list.GetItems(oQuery);

                            if ((null != collListItems) && (collListItems.Count >= 1))

                            {

                                result = GetValue(collListItems[0]);

                            }

                        }

                        catch (Exception ex)

                        {

                            Debug.WriteLine(ex.ToString());

                        }

                    }

                }

            }

            );

            return result;

        }

        const string globalMapCacheKey = "globalConfigurationMapCacheKey";

 

        private Dictionary<string, Dictionary<string, string>> GetMap()

        {

            Dictionary<string, Dictionary<string, string>> map = HttpContext.Current.Cache[globalMapCacheKey] as Dictionary<string, Dictionary<string, string>>;

            if (null == map)

            {

                map = new Dictionary<string, Dictionary<string, string>>();

                HttpContext.Current.Cache[globalMapCacheKey] = map;

            }

            return map;

        }

    }

}

 

The Provider just loads the implementation based on the class name and assembly name of an entry in the application settings in web.config.

// <summary>

    ///  

    /// Class, Assembly

    ///     <add key="configManagerProvider" value="ConfigurationManager, GlobalConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22d2dcb173b01686"/>

    /// </summary>

    public class ConfigurationManagerProvider

    {

        private const string configManagerProviderKey = "configManagerProvider";

        static public  IConfigurationManager GetConfigurationManager()

        {

            string str = WebConfigurationManager.AppSettings[configManagerProviderKey];

            int isep = str.IndexOf(',');

            string assemblyName = str.Substring(isep+1);

            string typeName = str.Substring(0,isep);

            Assembly asm = Assembly.Load(assemblyName);

            IConfigurationManager mngr = asm.CreateInstance(typeName) as IConfigurationManager;

            return mngr;

        }

    }

 

The consumer would write code similar to

      IConfigurationManager cm = ConfigurationManagerProvider.GetConfigurationManager();

      lblSiteTitle.Text = cm.GetConfiguration("Site1", "Key1");

 

{26/08/2010 1:47 PM} {0 Comments}  {Tags: SharePoint}
WCF and xsd:choice how to implement!
For some reason Microsoft decided that WCF serialization is not going to support the xsd:choice. The .Net XML serialization does support xsd:choice which is important. Now, if you had a schema that used xsd:Choice and used XSD tool to generate classes for it will generate code similar to:
///<remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Option1", typeof(typeOption11), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("Option2", typeof(typeOption2), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("Option3", typeof(typeOption3), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public object Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
Well that is look neat does not it? Now if you exposed this same generated code through WCF, the WSDL would generate item as Object on the client side and the consumer would not get any information from the WSDL about typeOption1, typeOption2, nor typeOption3. That is a real pain for the developer on the consumer side!. So one workaround that I had to device for a solution I was developing is to create another class like the following
public partial class Optionss {
 
    [System.Xml.Serialization.XmlElementAttribute("Option1", typeof(typeOption1), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption1 Option1 = null;
    [System.Xml.Serialization.XmlElementAttribute("Optoin2", typeof(typeOption2), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption2 Option2 = null;
    [System.Xml.Serialization.XmlElementAttribute("Option3", typeof(typeOption3), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption3 Option3 = null;
 
}
And chenage the item above to be similar to
    public Optionss Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
 
Now the options are going to appear to the consumer, however the data you receive is going to be for a different schema so I wrote code that would serialize the received request then “fix” the XML to be corresponding to the actual schema with xsd:choice.  Not quite neat  workaround but it works.
{06/08/2010 2:21 PM} {0 Comments}  {Tags: EAI, WCF, Web Developmenet}
WCF: Refactoring a Plain old XML web service to a WCF Service
Recently I was tasked to help devise a plan to refactor an application that was exposing non-compliant SOAP web services. I took a closer look at the application and decided that the best route would be to use the WCF to implement the refactored services. The old service had published XSDs for request and response of the web services. It was necessary to keep backward compatibility and keep these same XSDs valid for the new services.  With that in mind I devised the following plan
1.       Convert the schemas to CS classes using the XSD tool
2.       Create a new WCF Service Application
3.       On project click add existing items and add the two generated classes
4.       Rename the IService1.cs file to I[yourserviceName]Service.cs
5.       Change the Interface as follows
a. [ServiceContract(Namespace="your namespace")]
b.     [XmlSerializerFormat(Style=OperationFormatStyle.Document,Use=OperationFormatUse.Literal)]
 
6.       Include  a template for serializing and de-serializing classes (ObjectXMLSerializer.cs fond in downloads)  in your project
7. Rename the interface and change the method inside to have the form    
a. [OperationContract(Name = "Name", Action = "URL")]
b.              Response Service(Request req);
8.       Rename Service1.svc to Yourservicename.svc
9.       Open the code behind
10.   Rename the class and the inheriting interface
11.   Implement the method to be in form
    [ServiceBehavior(Namespace=”Your Name space ",IncludeExceptionDetailInFaults=true)]
   
    public class YourService : IYourService
    {
        public YourServiceResponse Service(YourServiceRequest req)
       
12.   Update the config.web file
      <servicename="YourServiceNameSpace.YourService"behaviorConfiguration="YourServiceNamespace.YOurService1Behavior">
                        <!-- Service Endpoints -->
                     <endpointaddress=""binding="wsHttpBinding"contract="YourServiceNameSpace.IYourService">
13.   Update the .svc file directive <%@ ServiceHost Language="C#" Debug="true" Service="YoursServiceNameSpace.YourService" CodeBehind="YourServiceService.svc.cs" %>
14.   Set .svc as the starting page press and the project as the starting project
15.   Now is the tricky part we add a Message wrapper class on the generated schema to control the message serialization, so  Open the CS Request Schema 
a.       ADD code similar to the following
using System.ServiceModel;
[MessageContract(IsWrapped = false)]
public class YourServiceRequest
{
    [MessageBodyMember(Name = "REQUEST", Namespace = "YourNameSpace")]
      public Request request;
}
b.      ADD code similar to the following
using System.ServiceModel;
[MessageContract(IsWrapped = false)]
public class YourServicesResponse
{
    [MessageBodyMember(Name="RESPONSE")]
    public Response response;
}
Press f5 you should see the service description press on WSDL and you will see the WSDL
Hope this helps:)
{18/05/2010 1:37 PM} {0 Comments}  {Tags: WCF}
Setting the ESB Toolkit on the 64 Bit Machines
1.       Make sure you have a viable BizTalk Environment with BAM Tools
2.       Install UDDI form BizTalk DVD and make sure it is configured properly
3.       Install MS Enterprise Library 4.1
4.       Install Microsoft Chart Controls for .Net 3.5
5.       Install Visual Studio 2008 SDK
6.       Install the MS BizTalk ESB Toolkit 2.0
7.       Run the ESB configuration tool located “C:\Program Files (x86)\Microsoft BizTalk ESB Toolkit 2.0\Bin\ESBConfigurationTool.exe”
8.       Now start configuration of the ESB toolkit which is a little bit tricky, you have to set the properties for each section and apply it before you can proceed to the next section. Unlike configuring BizTalk were you can set all section and click apply once.
9.       Start by configuring the Exception Management database make sure that there are no errors in red if there are then delete the database from the SQL server correct the errors and reapply. Not that the ESConfigurationTool is non transactional which means it would not create everything or nothing it can create the database but no table or stored procedures which would cause you a headache later on to figure out why the ESB toolkit is not working properly Read more.. 
{10/05/2010 12:28 PM} {0 Comments}  {Tags: BizTalk, ESB Toolkit}
The BizTalk ESB Toolkit 2.0 experience Series
In this series of blogs I will explain and discuss my experience with the MS ESB Tool kit for BizTalk 2009.  The BizTalk ESB Toolkit 2.0 is a collection of tools and libraries that extend BizTalk Server capabilities of supporting a loosely coupled and dynamic messaging architecture.  The two most valuable features of the toolkit are:
·        The Itinerary capabilities which allows you to implement a simple chain of actions on a message path (these actions can be running BizTalk maps, BizTalk Orchestration, or custom .Net code).
·        The Management portal sample  which allows you to view suspended messages and control other aspects of BizTalk and the ESB
The following figure for Microsoft shows the components of the BizTalk ESB Toolkit 2.0
 
Read more..
{08/05/2010 10:58 AM} {0 Comments}  {Tags: Architecture, BizTalk, EAI, ESB Toolkit}
1 2 3 4 5> >>|
Rss
 
BizTalkGear.com
BizTalk components
Genetic Thought Software Inc
Genetic Thought Web Site where you can by my software products
SodukuPro.com
Play Sudoku Online or buy a PC based edition

Rss
Key Subjects
  • BizTalk
  • EMail
  • SharePoint
  • Architecture
  • EAI
  • Exception Management
  • Web Developmenet
  • Deployment
  • Security
  • Busienss Rules
  • SQL Server
  • ESB Toolkit
  • WCF
Copyright © Moustafa Refaat 2004 - 2009. All Rights Reserved.