• How to create Pin Authorization Normalization rule in Lync

    I have got many requests on how to create Pin Authorization for specific users on lync to be able to dial international calls.

    Here’s a sample case scenario and print screen of the normalization rule that meets this case:

    - User has to type pin number before any dialed international number,  the pin number is #9090 and that will be shared with the user by the administrator in secured email.

    Scenario  1: User want to dial 0097466040129 he just type it directly , notice the highlighted test result below call will not succeed as it’s not normalized:

    AST-007

    Scenario 2:  User has to types the number in this format #9090009746040129 , notice the highlighted test result below the resulted number is +97466040129 call will succeed as it’s normalized correctly.

    AST-006

    The above is just an example that can be tailored according to different environments.

    Notes:

     - The above normalization rule should be duplicated for pin+E164 typed numbers.

    - Another normalization rule might be required to truncate the E164 numbers that are directly typed by users to bypass the pin enforcement. this rule will be deleting international numbers typed in E164 without the pin.

    I hope it helps !

  • My Hello Azure Service Bus WCF Service–Step by step guide

    This is the first post in a series to take you through my learning experience to using the Windows Azure service bus. The Service Bus is a concrete implementation of the service bus pattern designed to operate at Internet scope within highly-scalable Microsoft data centers as a constituent of the Windows Azure platform. The Service Bus provides a federated identity and access control mechanism through Access Control, a federated naming system, a dynamic service registry, and a robust messaging fabric capable of overcoming the internet and distributed services connectivity. The internet challenges that any distributed service platform face are summarized in the below diagram.

    clip_image002[4]

    The way that the service bus overcomes these challenges is by implementing a relay service pattern as below.

    clip_image004[4]

    Here’s how it works: the on-premises service connects to the relay service through an outbound port and creates a bidirectional socket for communication tied to a particular rendezvous address. The client can then communicate with the on-premises service by sending messages to the relay service targeting the rendezvous address. The relay service will then “relay” messages to the on-premises service through the bidirectional socket already in place. The client does not need a direct connection to the on-premises service nor does it need to know where it resides. The on-premises service doesn’t need any inbound ports open on the firewall. This is how most instant messaging applications work today.

    A central component of the Service Bus messaging fabric is a centralized (but highly load-balanced) relay service that supports a variety of different transport protocols and Web services standards, including SOAP, WS-*, and even REST.  The relay service provides a variety of different relay connectivity options and can even help negotiate direct peer-to-peer connections when possible.

    So in this article I will show you how to develop your first hello service hosted on the service bus. The major steps can be summarized as below.

    Step 1:               Create a new service bus namespace on the Azure service bus.

    Step 2:               Implement the service and client.

    Step 3:               Configure the service and client to use the required relay binding configuration.

    So as you can see it is as easy as 1, 2, and 3. Or is it?! J

    Step1: Create a new service bus namespace

    So you need to go to the URL: https://windows.azure.com/ that will request you either to login using a live ID that has already an active Azure subscription or to sign up. If you already have an account then just logon, or if not you can click sign up.

    clip_image006[4]

    That would lead you to the purchase screen of subscription options, study your options well and pick whatever type you want or (even better) click on the FREE trial.

    clip_image008[4]

    Then you will be asked to login using an existing live ID then you will need to go through three steps as below:

    clip_image010[4]

    clip_image012[4]

    Then in the third step you would need to enter a credit card just as a form of verification and voila you have a three month trial subscription on Azure.

    Next logon to your management portal using you live ID on the URL: https://windows.azure.com/ it should look something like this.

    clip_image014[4]

    Now to create a new namespace do the following steps.

    ·         Click on “Service Bus, Access Control & Caching” from the bottom left.

    ·         Then click on “Service Bus”
    clip_image016[4]

    ·         Then click “New”
    clip_image017[4]

    ·         Enter the namespace name and the portal will check if it is available or not for you and select the needed details as below:
    clip_image019[4]

    ·         Click “Create” and the namespace would be ready to use.

    ·         Now we will need three details to get started, the service hosting URL, the secret issuer name and issuer secret. The service hosting URL would be dependent on the namespace you already created so for the shown above example the URL would be: https://MyAzureHello.servicebus.windows.net.

    ·         To get the secret details click on the created namespace.
    clip_image021[4]

    ·         Then scroll the right action pan all the way down and click on “View” for the “Default Key”.
    clip_image023[4]

    ·         It will then give you the option to copy both the issuer name and the issuer secret to the clipboard. Do this one by one and keep this information were you can use it later.
    clip_image024[4]

    Step 2: Implement the service and client

    This is a straight forward step. Just create two console applications, one for the service host and another for the client and create a service definition as below.

    [ServiceContract]

    public interface IHelloServiceBus

    {

        [OperationContract]

        string SayHello(string name);

    }

    Listing 1: Service Contract

    public class HelloServiceBus : IHelloServiceBus

    {

        public string SayHello(string name)

        {

            string greeting = string.Format("Hello {0}!", name);

            Console.WriteLine("Returning: {0}", greeting);

            return greeting;

        }

    }

    Listing 2: Service Implementation

    static void Main(string[] args)

    {

        Console.WriteLine("**** Service ****");

        ServiceHost host = new ServiceHost(typeof(HelloServiceBus));

        host.Open();

     

        Console.WriteLine("Press [Enter] to exit");

        Console.ReadLine();

     

        host.Close();

    }

    Listing 3: Host Implementation

    static void Main(string[] args)

    {

        Console.WriteLine("**** Client ****");

        Console.WriteLine("Press <Enter> to run client.");

        Console.ReadLine();

        Console.WriteLine("Starting.");

     

        ChannelFactory<IHelloServiceBus> channelFactory =

            new ChannelFactory<IHelloServiceBus>("webRelay");

        IHelloServiceBus channel = channelFactory.CreateChannel();

     

        for (int i = 0; i < 10; i++)

        {

            string response = channel.SayHello("Service Bus");

            Console.WriteLine(response);

        }

     

        channelFactory.Close();

    }

    Listing 4: Client Implementation

    Now we need to configure both the client and service to use the service bus bindings.

    Step 3: Configure the service and client to use the required relay binding configuration

    All you need to do is to put the proper Azure service bus configuration. But before you do that how would the service and client implementation know where to get the binding implementation from? You did not add any custom references, right?! So here is how.

    ·         Make sure both the client and service is using the .NET 4 profile (not the client profile).

    ·         The go in Visual Studio to tools and then extension manager:
    clip_image025[4]

    ·         Click on line gallery and search for “NuGet”
    clip_image027

    ·         Click download and hence install the NuGet Package Manager.

    ·         Close the extension manager.

    ·         Right click on the references node for the service project and click “Manage NuGet Packages”.
    clip_image028

    ·         Click online.

    ·         Search for “Azure” and select the “Windows Azure Service Bus” and click  “Install”.
    clip_image030

    ·         Install the same NuGet package to the client project.

    ·         Now that you have the Azure assemblies in place you can change the service and client configurations as below.

    <system.serviceModel>

      <services>

        <service name="Service.HelloServiceBus">

          <endpoint address="https://momalek.servicebus.windows.net/helloservicebus" behaviorConfiguration="sharedSecretClientCredentials" binding="ws2007HttpRelayBinding" contract="Service.IHelloServiceBus"/>

        </service>

      </services>

      <behaviors>

        <endpointBehaviors>

          <behavior name="sharedSecretClientCredentials">

            <transportClientEndpointBehavior credentialType="SharedSecret">

              <clientCredentials>

                <sharedSecret issuerName="[Issuer name retrieved before]" issuerSecret="[issuer secret retrieved before]"/>

              </clientCredentials>

            </transportClientEndpointBehavior>

          </behavior>

        </endpointBehaviors>

      </behaviors>

    </system.serviceModel>

    Listing 5: Service Configuration

    <system.serviceModel>

      <client>

        <endpoint address="https://momalek.servicebus.windows.net/helloservicebus" behaviorConfiguration="sharedSecretClientCredentials" binding="ws2007HttpRelayBinding" contract="Service.IHelloServiceBus" name="webRelay"/>

      </client>

      <behaviors>

        <endpointBehaviors>

          <behavior name="sharedSecretClientCredentials">

            <transportClientEndpointBehavior credentialType="SharedSecret">

              <clientCredentials>

                <sharedSecret issuerName="[Issuer name retrieved before]" issuerSecret="[issuer secret retrieved before]"/>

              </clientCredentials>

            </transportClientEndpointBehavior>

          </behavior>

        </endpointBehaviors>

      </behaviors>

    </system.serviceModel>

    Listing 6: Client Configuration

    Now you are ready to start the service and (wait for it to properly start, as it take some time – couple of minutes or so) the client and watch them communicate through the Azure service bus.

    Final Notes

    During this exercise I tried many bindings and I must say that the most reliable one I used was the “ws2007HttpRelayBinding” (I mean reliable from the perspective of being able to start hosting the service with no problems).

    Hosting a service behind a proxy (specially a proxy that requires authentication) is not supported and does not workL. Check this URL: http://msdn.microsoft.com/en-us/library/windowsazure/ee706729.aspx.

  • Visual Round Trip Analyzer For SharePoint administrator

    Visual Round Trip Analyzer (VRTA) is a tool that helps the SharePoint Administrator identify
    what is being downloaded at a web page level.

    One of the biggest complaints from users is the response time.

     

    VRTA excels in showing the network round trip relationship between the client and the server.

    This is also critical to the well-being of a farm. While an administrator can optimize the server
    response, there are several other parties that can inadvertently be working against this:

    • Web developers: These folks create the HTML, CSS, and stylesheets.
    • End users: They load content such as images, which directly hampers performance.
    • Application developers: These folks load JavaScript, jQuery, and now have the client
      object model at their disposal.


    All of these listed parties create solutions using SharePoint Designer, Notepad, and possibly
    Visual Studio, and the administrator would have no knowledge of this. But in the end, the
    administrator is the person who will get the support call.

    Using VRTA, the administrator can identify the bottlenecks and involve the right parties.

     

    You must have VRTA loaded on a PC (free download from the Microsoft Download Center).
    Netmon 3.4, also a free download, needs to be loaded on the PC. These tools should not be
    run on servers but on local machines. No special permissions are needed and it can be run
    against a public site.

    VRTA uses Microsoft Network Monitor 3.4 packet analyzer as its foundation. Visually, it shows
    files and packets, along with the round trip information that occurs between a client
    and server.

    When evaluating page loads, several factors should be taken into account:

    • Distance: The round trip
    • Number of round trips
    • Images on a home page
    • Files that need to be downloaded (CSS, JavaScript, and so on)

     

    image

    Using the four tabs, Main Chart, Statistics, All Files, and Analysis, the data the page is
    retrieving and loading can be seen in detail. In the preceding screenshot, every file that is
    loaded shows how long to load, the port, the type of file, a status code, and size.


    The administrator can observe the assets that are being used
    and be able to offer recommendations such as creating a sprite instead of loading each
    individual image, or combining JavaScript files. Hovering over each detail item will present
    further detail on the individual asset.


    VRTA also has an Analysis tab that acts as a best practice guide. It grades the files and page
    on several basic factors such as an average file size rule, white spaces rule, and image
    clustering rule. Using a color-coded scheme, it makes recommendations to help you
    improve performance.


    Finally, every time a recording is made, it is saved in a directory by default, whose path can be
    seen in the title of the VRTA application.

  • TFS 2010 in Practice –Import Upgrade from 2005/2008

    Introduction

    Hello again. In the first part we have done an introduction to TFS 2010 and installation according to dual-server topology. In this post, we will talk about migrating existing TFS databases into TFS 2010 platform. We shall start!

    Firstly, before we are getting into details of importing upgrade, I would like to mention other types of scenarios you might encounter:

    • Migrating sources from 3rd party servers as like IBM Rational ClearCase or ClearQuest, Perforce, HP QualityCenter, Subversion: You can use TFS Integration Tool (1) that is developed by MS TFS product group and ALM Rangers. In fact, the tool can be used for synchronization between those platforms as well. It can also be used for import upgrade scenarios which is defined below. Although I have not tried this, it is very promising. For more details please visit here
    • In-Place Upgrade: Simply upgrading from old version of TFS (2005/2008) to 2010 within the same box by selecting Upgrade from TFS Installation wizard. No need to use another tool. For detail please visit 1st part of these series.

    How-To

    So, here we have TFS 2010 that is up and running well and now wants to import content of TFS 2008 server (applies to TFS 2005 as well). One of the biggest differences between 2010 and old version is that 2010 is based on Team Project Collections (TPCs): One collection reflects a single database and may have 0 or more team projects, independent from other TPC.

    Steps:

    1. Inform your team members about process and schedule
    2. Back up all TFS databases (both from and to databases)
    3. RDC to TFS server (where TFS 2010 installed), make sure the account has permissions to from-and-to-databases. I have used tfs.setup account which is local administrator in TFS 2010 machine and has access rights to databases. For detail again please look at the first part.
    4. Run Command Prompt with administration privilege (type “cmd /admin” in run section of start menu)
    5. Tfsconfig.exe is located in “%programfiles%\Microsoft Team Foundation Server 2010\Tools” directory, so please cd to here in the prompt window
    6. Type “Tfsconfig import /sqlinstance:<FromDatabaseServerInstance\FromDatabase> /collectionName:<CollectionName> confirmed”. This will take some time depending on the network and size of the from-database content, in my case it took 45-50 minutes. At the end if you don’t have 0 error/warning means it is succeed!
    7. Configure portal (on SharePoint Foundation) and reports

    clip_image002Picture 1: Arguments of tfsconfig.exe

    Data Model in TFS 2010

    Databases used by TFS 2010 with some notes

    • ReportServer
    • ReportServerTempDB
    • SharePoint_AdminContent_#: Please remember that SharePoint Foundation 2010 used instead of WSS 3.0
    • SharePoint_Config: portal configuration
    • Tfs_Configuration: central database include list of TPCs
    • Tfs_Warehouse: where data about team project collections is stored and optimized for reports
    • Tfs_DefaultCollection: Again, 2010 creates a database per each TPC that stores collection related data (source, work items, builds, etc..).
    • WSS_Content
    • WSS_Search

    clip_image004

    Picture 2: TFS 2010 SQL Database, Tfs_Warehouse

    Health Check

    After importing it would be wise to re-run Best Practice Analyzer, just you do before importing process. To do so,

    1. Install Microsoft Team Foundation Server Power Tool (2). You should have this tool not just for server analysis, but for TFS Backups configuration and scheduling, Custom Check-in policies, Team Explorer enhancements, Team Members collaboration, etc.
    2. Start > Programs > Microsoft Team Foundation Server Power Tool > Team Foundation Server Best Practices Analyzer

    clip_image006

    Picture 3: TFS 2010 Best Practices Analyzer running

    Conclusion

    In this second part, we have executed a scenario of importing TFS 2005/2008 databases into TFS 2010 Server by using tfsconfig command. Hope you liked it.

    Refererences

    1. TFS Integration Platform
    2. Team Foundation Server Power Tools
    3. Team Foundation Server – Migration and Integration
    4. Moving Team Foundation Server
  • Implementing a message pass-through WCF Behaviour (Router WCF service)

    I recently came across a requirement to implement a Windows Communication Service that acts as a message router across several other WCF backend services. This router service main functionality is to encapsulate the backend services and also to add automatic request monitoring. This should not be hard I was thinking but there are couple of twists, first the router service should not sensitive to the services themselves and how they change and communicate with their clients. It also will be handing encrypted messages that it cannot decrypt as these messages belong to other partners that we do not control and of course do not have the certificate used for encryption.

    The way this is done is by implementing custom WCF message dispatch inspector and custom WCF message client message inspector behaviours. Why do we need both as our service acts as a WCF to all the clients and as a client to all the backend services. So the main idea is to when a message is received over the wire the entire message body is escaped and placed in a custom header element and before this message is sent to the backend the original message body is extracted from the header and written back to the message sent. While the response is being received from the backend service the same logic happens but in the reverse order. So the reply is written to the custom header as an escaped string and then before this reply is delivered to the original caller the reply is read from the header and sent to the client. Simple right J well it will get even better; since we want the original message unparsed and not changed coming on the wire this has to be done using a custom message encoder for both ways, receiving requests from the clients and receiving responses from the backend services. So to try to make this simple I placed the following diagram.

    clip_image002[4]

    So you need to implement a custom message encoder inheriting from the class “MessageEncoder” and mainly implement the method “ReadMessage” to be as follows.

            public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)

            {

                byte[] msgContents = new byte[buffer.Count];

                Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);

                bufferManager.ReturnBuffer(buffer.Array);

     

                MemoryStream stream = new MemoryStream(msgContents);

                Message message = ReadMessage(stream, int.MaxValue);

     

                string ns = "http://Somenamespace";

     

                MessageHeader header = MessageHeader.CreateHeader("OriginalFullMessage", ns, UTF8Encoding.UTF8.GetString(msgContents));

                message.Headers.Add(header);

     

                return message;

            }

    So you need to implement first a custom class inheriting from “IDispatchMessageInspector” and it should first override the method “ApplyDispatchBehavior” to add this dispatch behavior to the endpoint as follows.

            public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)

            {

                endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);

                endpointDispatcher.AddressFilter = new System.ServiceModel.Dispatcher.MatchAllMessageFilter();

            }

    Then you need to implement the method “BeforeSendReply” to put the original reply back on the wire as follows.

            public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)

            {

                string origMsg = OperationContext.Current.RequestContext.RequestMessage.ToString();

                string fullMessageHeader = "OriginalFullMessage";

                string ns = "http://Somenamespace";

                int fullMessageHeaderIndex = reply.Headers.FindHeader(fullMessageHeader, ns);

                if (fullMessageHeaderIndex >= 0)

                {

                    origMsg = UnescapeXml((reply.Headers.GetHeader<string>(fullMessageHeaderIndex)));

                }

     

                Message newreply = Message.CreateMessage(MessageVersion.None, reply.Headers.Action, new SimpleMessageBody(origMsg));

     

                newreply.Headers.To = reply.Headers.To;

                reply = newreply;

                return;

            }

    You will then need to implement the method “BeforeSendRequest” from the class “IClientMessageInspector” to put the original request back on the wire before we send it to the backend services.

            public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)

            {

                string origMsg = OperationContext.Current.RequestContext.RequestMessage.ToString();

                string fullMessageHeader = "OriginalFullMessage";

                string ns = "http://Somenamespace";

                int fullMessageHeaderIndex = request.Headers.FindHeader(fullMessageHeader, ns);

                if (fullMessageHeaderIndex >= 0)

                {

                    origMsg = UnescapeXml((request.Headers.GetHeader<string>(fullMessageHeaderIndex)));

                }

     

                Message newRequest = Message.CreateMessage(MessageVersion.None, request.Headers.Action, new SimpleMessageBody(origMsg));

     

                newRequest.Headers.To = request.Headers.To;

                request = newRequest;

     

                return null;

            }

     

    And that’s it J