in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

ožujak 2012 - Posts

  • Support for .NET framework on Windows 8

    There are currently log of discussions and confusion in relation to Windows 8 and support for several technologies. These days I was asked about support for .NET 4.0 and .NET 4.5.. So I tried to collect various official information (excluding all internal statements) an put it all together here. First of all, it is important to know that Windows 8 will not support .NET 4.0. Some companies which already invested in .NET 4.0 seem to be scared about this. Fortunately this fact has nothing to do with some technology deprecation (MS never did that without giving support for 10 years (at least as I remember).

    More interesting is that .NET Framework 4.5 is an in-place update that replaces .NET Framework 4 (rather than a side-by-side installation). This has nothing to do with Windows 8. NET 4.5 is (designed to be – look here for breaking changes) fully backward compatible with applications built for .NET 4 (.NET 3.5 and .NET 4.5 will be side-by-side). .NET 4.5 is build with version 4.0.30319. This is technically the same version as .NET 4. .NET Devs know that  this practice is used for so called  in-place updates.
    So, Windows 8 will be delivered with .NET framework 4.5 and this will by default provide support for .NET 4.0 applications, because 4.5 is technically 4.0 main stream.
    Here is a nice overview of .NET delivery at various windows operative systems.

    Components and Layers of .NET Framework versions

    Posted ožu 29 2012, 09:45 by anonymous
    Filed under:
  • ServiceBus 1.0 and 1.6 side by side


    I had a strange problem few days ago with one ServiceBus application. The application has been tested successfully, but imagine it didn’t work in production (in this case stage-system).
    This seems to be a standard pattern in a life of one software developer. The error was like:

    “error: "MissingToken: Relay security token is required"

    Uups.

    However, there also a common pattern in the life of same person called “Never trust an error message” (especially not if it is translated in another language from English).

    So I figured out, that Microsoft.ServiceBus.dll 1.0 was already installed on the production machine. Remember, this assembly was at the beginning always registered in GAC. Since v. 1.6 this is no more the case. So, the application was basically executed against old version of Service Bus.

    image

    Racap: Remove 1.0 before installing 1.6. The version 1.6 which is installed by November 2011 Windows Azure SDK release will not remove the existing version automatically.

    Hope this never happen to you. See here for more information about different version of Windows Azure SDK.

  • Proxy generated by SignalR on the fly

    When the JavaScript renders script tag which includes/imports signal/rhubs the JavaScript proxy file will be generated. Commonly the JavaScript will include this virtual (none existing) script with following line:

    <script src="/Daenet.SignalR/signalr/hubs" type="text/javascript"></script>

    SignalR will receive this request and will generate the proxy classe which can be used to access hubs in the MVC manner. To make this working SignalR will generate following JavaScrip proxy on the request: http://localhost/VirtualFolder/signalr/hubs

    (function ($, window) {
        /// <param name="$" type="jQuery" />
        "use strict";

        if (typeof ($.signalR) !== "function") {
            throw "SignalR: SignalR is not loaded. Please ensure jquery.signalR.js is referenced before ~/signalr/hubs.";
        }

        var hubs = {},
            signalR = $.signalR,
            callbackId = 0,
            callbacks = {};

        // Array.prototype.map
        if (!Array.prototype.hasOwnProperty("map")) {
            Array.prototype.map = function (fun, thisp) {
                var arr = this,
                    i,
                    length = arr.length,
                    result = [];
                for (i = 0; i < length; i += 1) {
                    if (arr.hasOwnProperty(i)) {
                        result = fun.call(thisp, arr, i, arr);
                    }
                }
                return result;
            };
        }

        function executeCallback(hubName, fn, args, state) {
            var hub = hubs[hubName],
                hubMethod;

            if (hub) {
                signalR.hub.processState(hubName, hub.obj, state);

                if (hub[fn]) {
                    hubMethod = hub.obj[fn];
                    if (hubMethod) {
                        hubMethod.apply(hub.obj, args);
                    }
                }
            }
        }

        function updateClientMembers(instance) {
            var newHubs = {},
                obj,
                hubName = "",
                newHub,
                memberValue,
                key,
                memberKey;

            for (key in instance) {
                if (instance.hasOwnProperty(key)) {

                    obj = instance[key];

                    if ($.type(obj) !== "object" ||
                            $.inArray(key, ["prototype", "constructor", "fn", "hub", "transports"]) >= 0) {
                        continue;
                    }

                    newHub = null;
                    hubName = obj._.hubName;

                    for (memberKey in obj) {
                        if (obj.hasOwnProperty(memberKey)) {
                            memberValue = obj[memberKey];

                            if (memberKey === "_" ||
                                    $.type(memberValue) !== "function" ||
                                    $.inArray(memberKey, obj._.ignoreMembers) >= 0) {
                                continue;
                            }

                            if (!newHub) {
                                newHub = { obj: obj };

                                newHubs[hubName] = newHub;
                            }

                            newHub[memberKey] = memberValue;
                        }
                    }
                }
            }

            hubs = {};
            $.extend(hubs, newHubs);
        }

        function getArgValue(a) {
            return $.isFunction(a)
                ? null
                : ($.type(a) === "undefined"
                    ? null
                    : a);
        }

        function copy(obj, exclude) {
            var newObj = {};
            $.each(obj, function (key, value) {
                if ($.inArray(key, exclude) === -1) {
                    // We don't use "this" because browser suck!
                    newObj[key] = value;
                }
            });

            return newObj;
        }

        function serverCall(hub, methodName, args) {
            var callback = args[args.length - 1], // last argument
                methodArgs = $.type(callback) === "function"
                    ? args.slice(0, -1) // all but last
                    : args,
                argValues = methodArgs.map(getArgValue),
                data = { hub: hub._.hubName, action: methodName, data: argValues, state: copy(hub, ["_"]), id: callbackId },
                d = $.Deferred(),
                cb = function (result) {
                    signalR.hub.processState(hub._.hubName, hub, result.State);

                    if (result.Error) {
                        if (result.StackTrace) {
                            signalR.hub.log(result.Error + "\n" + result.StackTrace);
                        }
                        d.rejectWith(hub, [result.Error]);
                    } else {
                        if ($.type(callback) === "function") {
                            callback.call(hub, result.Result);
                        }
                        d.resolveWith(hub, [result.Result]);
                    }
                };

            callbacks[callbackId.toString()] = { scope: hub, callback: cb };
            callbackId += 1;
            hub._.connection().send(window.JSON.stringify(data));
            return d;
        }

        // Create hub signalR instance
        $.extend(signalR, {
            myHub: {
                _: {
                    hubName: 'Daenet.SignalR.MyHub',
                    ignoreMembers: ['doWork', 'namespace', 'ignoreMembers', 'callbacks'],
                    connection: function () { return signalR.hub; }
                },

                doWork: function (message, callback) {
                    return serverCall(this, "DoWork", $.makeArray(arguments));
                }
            }
        });

        signalR.hub = signalR("/Daenet.SignalR/signalr")
            .starting(function () {
                updateClientMembers(signalR);
            })
            .sending(function () {
                var localHubs = [];

                $.each(hubs, function (key) {
                    var methods = [];

                    $.each(this, function (key) {
                        if (key === "obj") {
                            return true;
                        }

                        methods.push(key);
                    });

                    localHubs.push({ name: key, methods: methods });
                });

                this.data = window.JSON.stringify(localHubs);
            })
            .received(function (result) {
                var callbackId, cb;
                if (result) {
                    if (!result.Id) {
                        executeCallback(result.Hub, result.Method, result.Args, result.State);
                    } else {
                        callbackId = result.Id.toString();
                        cb = callbacks[callbackId];
                        if (cb) {
                            callbacks[callbackId] = null;
                            delete callbacks[callbackId];
                            cb.callback.call(cb.scope, result);
                        }
                    }
                }
            });

        signalR.hub.processState = function (hubName, left, right) {
            $.extend(left, right);
        };

    } (window.jQuery, window));
    0

    The proxy shown above has been generated for following hub class:

    public class MyHub : Hub

        {

            public void DoWork(string message)

            {

                Clients.addMessage(message);

            }      

     

        }

    The JavaScript code which access the hub looks in this case like:

    var myHub = $.connection.myHub;

    More about hubs an GitHub: https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs,
    https://github.com/SignalR/SignalR/wiki/SignalR-Client-Hubs

  • Windows Azure EDI Update

    The EDI bits on Azure have been refreshed without any service downtime!

    Specifically here are the new features:

    1. Delete agreement: Existing and new agreements can be deleted to reduce clutter and free up resources.
    2. Redeploy agreement: You can change agreement settings and redeploy the agreement

    EDI Portal performance is improved improved. Additionally error messages have been corrected/improved..

    You can access the new features through the EDI Portal https://edi.appfabriclabs.com. Please note that neither the existing functionality nor the existing partner and agreement data should be affected by the update.

  • Microsoft Network 2: Get Ready for Windows Azure


    Announcing the session about Solution Architectures for Cloud, None-Cloud and hybrid applications. n this session you will learn about new possibilities around number of Windows Azure Services which provide new possibilities for applications running On-Premise, in the cloud or both. This demo-powered session will focus on powerful solution architecture patterns around Caching, Remoting, Tunneling, Relaying, brokering with Message Queue, Topics and more. The focus of session is not only development of Cloud applications. Even more, we will also focus on development of applications which do not run necessarily in the cloud, but make usage of Windows Azure services and related patterns.

    The session content targets every Windows and also none- Windows developers and architects who want to get ready for cloud.
    Key messages:

    - Learn how to design On Premise, Cloud and Hybrid applications
    - See how new communication styles can be applied to set right solution architecture for cloud, none-cloud and hybrid applications
    -  Prepare to build On Premise applications today, which can run in Cloud tomorrow

    When: 05.04.2012 09.00 – 10.00h
    Add to your calendar.

  • Microsoft Network 2.0: ASP WebApi & Co.

    Announcing the session about Business and Mobile Platform evolution focused on ASP.NET WebApi and ASP.NET MVC 4.5. I’m still not sure how the final title of the session will be pronounced, but never mind. We already know what we will present.

    In past decade WCF has definitely grove in the most powerful communication technology targeting SOAP as underlying protocol for message exchange. However applications are continually evolving to expose their functionality over the web. Some of them popular social services like Facebook achieve a REST as a major communication style. So we will focus now to simplification of communication stack. WCF has focused Business Platform. WEP API should focus mobile and business platforms.
    This session is interesting is the story about the next step in evaluation of communication platform which allows developers to expose their applications, data and services to the web directly over HTTP.

    In this session you will learn not only about ASP WebApi. Even more we will talk about SOAP and REST, SOA and Web, Applications and Apps, GET and POST and, and, and….,

    You are invited to see the new API for web which is more than just REST. See also what Bahro posted about this.

    Who: Bahro & Damir (Huso I Haso)
    When: 04.04.2012 14.30 – 15.30h
    Add to your calendar.

  • How to enable VPN on Windows 8?

    To enable VPN on Windows 8 go to open search, select settings and search for VPN. Click on VPN and enter the VPN IP address and credentials. The connection to VPN will unfortunately fail. The reason for this is that Windows 8 has higher security requirements than previous operative systems.
    Following picture shows three settings which have to be changed to enable Windows 8 to connect to existing VPN server.

    image

    Please note that this setting provides less security than default one.

  • How to perform OAuth with Java Script?

    OAuth is in the moment possibly the most standard way to authenticate user in the world of REST, WEB and mobile devices. In this post I will show how to implement WRAP 0.9 authentication by using Windows Azure Access Control Service. Following Java Script function prepares and posts  the request as expected by Access Control Service and retrieves the Simple Web Token.

            CreateToken = function (userName, pwd, scope) {

               
    if (m_IsInitialized == null || m_IsInitialized == false
    )
                   
    throw "SecurityTokenClient.Initialize(config) has to be called."
    ;

               
    var data = "wrap_name=" + userName + "&wrap_password=" + pwd + "&wrap_scope="
    + scope;

                $.support.cors =
    true; // force cross-site scripting (as of jQuery 1.5)

                $.ajax({
                    type:
    'POST'
    ,
                    url: “https://yournamespace.accesscontrol.windows.net/WRAPv0.9/”,
                    context:
    "ctx"
    ,
                    data: data,
                    success:
    function
    (result) {
                        alert(“Hello token:” + result);
                    },
                    error:
    function (XMLHttpRequest, textStatus, errorThrown) {
                       
    alert(textStatus + “ – “ + errorThrown);
                    }
                });
            }


    Note that this function will fail in an ASP.NET application, because of browser cross-scripting limitation. Fortunately all mobile devices will allow execution if following line is executed:

    $.support.cors = true;

    I have encapsulated all of this in a Java Script module called SecurityTokenClient and tested it in the Windows Metro Style application. By using this module the authentication would look like shown in next METRO-example:

    <!DOCTYPE html>
    <
    html
    >
    <
    head>
        <meta charset="utf-8">
        <title>Application1</title>
        <!-- WinJS references -->
        <link href="//Microsoft.WinJS.0.6/css/ui-dark.css" rel="stylesheet">
        <script src="//Microsoft.WinJS.0.6/js/base.js"></script>
        <script src="//Microsoft.WinJS.0.6/js/ui.js"></script>
        <!-- Application1 references -->
        <link href="/css/default.css" rel="stylesheet">
        <script src="/js/default.js"></script>
        <script src="/js/jquery-1.6.3.js" type="text/javascript"></script>
        <script src="/js/knockout-2.0.0.js" type='text/javascript'></script>
        <script src="/js/jquery.fixedheadertable.min.js" type="text/javascript"></script>
        <script src="/js/query.model.js" type="text/javascript"></script>
        <script src="/js/query.presenter.js" type="text/javascript"></script>
        <script src="/js/sts.js" type="text/javascript"></script
    >
    </
    head
    >
    <
    body>
       
           
    <h3>Welcome to Windows Metro OAuth sample.</h3>
            <br/><br/>
            <button id="btn" type="button" >Click to get token.</button>
            <br/><br/>
            <div id="token">

            </div>
        <script type="text/javascript">


            //
            // This function will be called when service query operation has completed.
            var onQueryCompleted = function
    (error) {
               
    if (error != null
    )
                    alert(error);

                model = QueryPresenter.ViewModel();
            }

           
    //
            // This function will be after authentication has comleted successfully.
            var onAuthenticationCompleted = function
    (swt) {
               
                $(
    "#token"
    ).html(swt);
            }


           
    //
            // This function will be invoked when credentials have to be provided or
            // if the authentication has failed.
            var onAuthenticationError = function
    (err) {

               
    if (err == "User not authenticated!"
    ) {
                    QueryPresenter.LogOn(
    "user1", "123abc"
    );
                    $(
    "#token").html("Authenticating user1..."
    );
                }
    else
    {
                    $(
    "#token"
    ).html(err);
                }
            }


            $(document).ready(
    function
    () {

                $(
    "#btn").click(function
    () {
                    SecurityTokenClient.Initialize(
                       {
                           OnAuthenticationError: onAuthenticationError,
                           OnAuthenticationCompleted: onAuthenticationCompleted,
                           StsUrl
    : “https://yournamespace.accesscontrol.windows.net/WRAPv0.9/”,             
                      
    });

                    SecurityTokenClient.CreateToken("user1", "123abc", "http%3a%2f%2flocalhost%2fServiceApp");
                });
             

           
    });
       
    </script
    >
    </
    body
    >
    </
    html
    >

    In fact the whole authentication by using this module would look simplified like:

                $("#btn").click(function () {
                    SecurityTokenClient.Initialize(
                       {
                           OnAuthenticationError: onAuthenticationError,
                           OnAuthenticationCompleted: onAuthenticationCompleted,
                          
    StsUrl: “https://yournamespace.accesscontrol.windows.net/WRAPv0.9/”,          

                      });

                    SecurityTokenClient.CreateToken("user1", "123abc", "http%3a%2f%2flocalhost%2fServiceApp");
                });


    As you see, the module needs to be initialized and CreateToken has to be called. All other code shown in the example above is a bit sugar around UI.  And here is the full module implementation:

    /*
        Copyright daenet GmbH
      
    */



    //
    //  Provides the functionality for OAuth authentication.

    SecurityTokenClient = (function
    () {

       
    var
    m_QuaGGbdg;

       
    //
        // The URL of the Security Token Service.
        var
    m_StsUrl;

       
    //
        // Callback invoked if authentication has failed.
        var
    onAuthenticationError;

       
    //
        // Callback invoked if authentication has been successfully completed.
        var
    onAuthenticationCompleted;

       
    var
    m_IsInitialized;

       
    return
    {

           
    //
            // Gets the token.
            GetToken: function
    () {
               
    return
    m_QuaGGbdg;
            },

           
    //
            // True if the SWT token exists.
            isAuthenticated: function
    () {

               
    if (m_QuaGGbdg != null
    ) {
                   
    return true
    ;
                }
               
    else
    {
                   
    return false
    ;
                }
            },

           
    //
            // If the client is not authenticated it invokes onAuthenticationError
            // and returns FALSE.
            // If the client is authenticated it returns TRUE.
            EnsureAuthenticated: function
    () {

               
    if (this.isAuthenticated() == false
    ) {
                    onAuthenticationError(
    "User not authenticated!"
    );
                }
            },

           
    //
            // Initialize the client for communication with STS.
            Initialize: function
    (config) {

               
    if (config != null
    ) {
                   
    if (config.OnAuthenticationError == null
    )
                       
    throw "onAuthenticationError handler has to be registered!"
    ;

                   
    if (config.OnAuthenticationCompleted == null
    )
                       
    throw "onAuthenticationCompleted handler has to be registered!"
    ;

                   
    if (config.StsUrl == null
    )
                       
    throw "StsUrl config parameter has to be set!"
    ;

                    onAuthenticationError = config.OnAuthenticationError;

                    onAuthenticationCompleted = config.OnAuthenticationCompleted;

                    m_StsUrl = config.StsUrl;

                    m_IsInitialized =
    true
    ;
                }
               
    else
                    throw "Configuration parameters have not been specified."
    ;

            },


           
    //
            // Performs the OAuth authentication.
            // userName: The user ot be authenticated.
            // pwd: The user's password.
            // scope: Trusted audience (realm).
            CreateToken: function
    (userName, pwd, scope) {

               
    if (m_IsInitialized == null || m_IsInitialized == false
    )
                   
    throw "SecurityTokenClient.Initialize(config) has to be called."
    ;

               
    var data = "wrap_name=" + userName + "&wrap_password=" + pwd + "&wrap_scope="
    + scope;

                $.support.cors =
    true; // force cross-site scripting (as of jQuery 1.5)

                $.ajax({
                    type:
    'POST'
    ,
                    url: m_StsUrl,
                    context:
    "ctx"
    ,
                    data: data,
                    success:
    function
    (result) {
                        m_QuaGGbdg = result;
                        onAuthenticationCompleted(result);
                    },
                    error:
    function (XMLHttpRequest, textStatus, errorThrown) {
                       
    onAuthenticationError(textStatus, errorThrown);
                    }
                });
            }
        }
    })();



  • .NET Leak Hunting wit SOS

    In last at least 10 years I figured out that a day of .NET managed developer is more easier than a day o C++ dev. In the decade before .NET I was spending a majority of a time by looking foe memory overruns and memory leaks. If you ever did such job for a longer time you will agree that not an amazing task. Unfortunately there are also situation when .NET  application can leak too. Thinking positive I always say “Be happy that memory overruns are gone at least”.
    My intension with this post is simply to paste few words which helps (me or you) tomorrow to remember what is my favor way to fix such issues. I really like very much Visual Studio and all those tools around it. But in very hard cases, which are according to murphy's low common cases all these tolls do not help much instead of one; the hardest one. Sun of Strike.

    It is installed in folder: %windir%\Microsoft.NET\Framework\<version>\sos.dll

    To load it in VS, type following command line in Immediate Window:

    .load sos

    When looking for leaks type !dumpheap -type MyNamespace.MyType

    This command dumps the portion of heap space occupied by instances of type MyNamespace.MyType. You can also type MyNamespace only and SOS will show the heap occupied by instances of all types of that namespace. I usually implement an endless loop in some part of program which probably leaks and stop after few steps in the loop to take a look on instance counter. In the case below this is 8.

    !dumpheap -type MyNamespace.MyType
    Address       MT     Size
    026fe21c 04999024      272    
    026ff2f4 04999024      272    
    0278610c 04999024      272    
    0278be1c 04999024      272    
    027fcc00 04999024      272    
    0281d258 04999024      272    
    0288cde4 04999024      272    
    028ace3c 04999024      272    
    total 0 objects
    Statistics:
          MT    Count    TotalSize Class Name
    04999024               2176 MyNamespace.MyType
    Total 8 objects

    This is how I do it. If anybody has better I would like to hear.

    Posted ožu 09 2012, 05:46 by anonymous
    Filed under:
  • Fiddler Protocol Violation

    Are you getting crazy because of “Fiddler Protocol Violation”, which forces you to press “ENTER” nx100 times or to kill fiddler process? This HTTP error seems to be caused by outlook “/rpc/rpcproxy” requests.

    image

    To prevent fiddler to get crazy on such errors do following:

    image

    Just check-out the check-box shown above.In picture above fiddler will show all violations.

    Posted ožu 08 2012, 04:58 by anonymous
    Filed under:
Copyright of SQL/Developers Community
Powered by Community Server (Commercial Edition), by Telligent Systems