in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

studeni 2011 - Posts

  • X509 Certificate flow in Windows Azure Access Control Service

    The picture below shows flow of X509 certificate in the communication between Client and Service by using WCF and Windows Azure Access Control service, Whe using this scenario you will be definitely confused at least by number of certificates used in communication process. Hope this picture can help a bit.
    image

  • WCF Duplex via WebSocket

    Long time ago WCF has introduced DUPLEX channels (bindings). A duplex service, can send messages back to the client endpoint, providing event-like behavior. Duplex communication is established when one client connects to a service and provides the service with a channel on which the service can send messages back to the client. The idea behind duplex is very nice and promising. Unfortunately there are few limitations which prevents this pattern to be widely used in almost all scenarios.
    For example, duplex works on top of the session which is established between client and the service. If this session is broken the callbacks cannot be invoked etc., etc..
    Moreover, if the client is invoking the service operation from internet location which is hidden by firewall NAT, the service will not be able to reach the client.
    In fact, Duplex has infrastructural and pattern driven limitations.

    This should be slightly changed in WCF 4.5. The WCF 4.5 introduces new binding NetHttpBinding, which establishes the duplex-session on top of WebSocket protocol. This protocol allows calling back operation event if the client is behind the firewall.

    How does this can work?

    On the beginning of the session client sends the typical HTTP request to service. This request contains a few more header like Upgrade-, Sec-WebSocket-Version-, Sec-WebSocket-Key header etc. After that Binding can use polling or it can open the permanent TCP connection between client and service (ConnectionMode= Upgrade/Allowed).
    Today we expect that TCP connection which is basically TCP- streaming between client and service established after first HTTP-request. This is very powerful mechanism to establish real time communication are real evening. Remember Duplex was as a pattern the simulation of evening. If the connection is not upgraded the polling will still be just a simulation of evening. However what ever the connection mode is used, the NAT issue is behind us. It will just work.

    Please do not confused with other implementations of websockets. At the moment there are four implementations.Not all of them provides the same thing.
    For example, following four libraries provides the functionality around WebSocket specification. They all are compatible with each other. Note that .NET implementation of the client functionality is missing and as I know it is unfortunately currently not at Microsoft Agenda. That means, if you want to use WebSockets as a .NET client you will have to use WinRT Windows.Networking.Sockets.Dll.

    Microsoft.ServiceModel.WebSockets
    Provides the native WebSocket  Server implementation which can be hosted on top of WCF. (See WebSocketService)

    Microsoft.Web.WebSockets
    Provides the native WebSocket Server implementation of WebSockets handlers in ASP.NET and ASP.NET MVC. (See WebSocketHandler)

    WIndows.Networking.Sockets
    WinRT implementation of WebSocket client functionality .

    Java Script
    Browser imlementation of client functionality, curentlly suported on IE10 only (in the Windows world)

    Last but not least, the namespace System.ServiceModel contains the Duplex implementation based of WebSockets. You cannot use this one in combination with any of libraries listed above. This post is related to this namespace only! Don’t get confused.

    Let’s build one sample

    Service

    Following code-snipet shows the service contract related to CallBack-ISampleServiceCallback .

    namespace Service

    {

        [ServiceContract(Namespace="http://daenet.com/orderservice",

                         CallbackContract = typeof(ISampleServiceCallback))]
        public interface ISampleService
        {

            [OperationContract]
            bool CreateOrder(long productId, int amount, long customerId);
        }

    }



    An this is how the callback contract is designed:

    namespace Service
    {
        [ServiceContract]
        public interface ISampleServiceCallback
        {
            [OperationContract(IsOneWay=true)]
            void OrderPurchased(long orderId, string comment);
     

            [OperationContract(IsOneWay = true)]
            void OrderCanceled(string reason);       

        }
    }

    An here is the the service implementation:

     

    namespace Service
    {
        public class SampleService : ISampleService
        {
            private static Dictionary<Guid, ISampleServiceCallback> m_CallbackChannels =

                new Dictionary<Guid, ISampleServiceCallback>();
     

            public bool CreateOrder(long productId, int amount, long customerId)
            {
                var ctxId = Guid.NewGuid();
     

                m_CallbackChannels.Add(ctxId,  OperationContext.Current.GetCallbackChannel<ISampleServiceCallback>());
     

                new Thread(new ThreadStart(delegate() 
                    {
                        Thread.Sleep(5000);
                       

                        if (amount > 10)
                            m_CallbackChannels[ctxId].OrderCanceled("Not in store");
                        else
                            m_CallbackChannels[ctxId].OrderPurchased(new Random().Next(10000), "Purchased successfully");
                    })).Start();
                return true;
            }
        }
    } 

    To make this working we will need a peace of configuration. This is a part of web.config file. That means I used IIS8 to host the web socket. This is important, because to host WebSockets you need to enable WebSocket protocol which is at the moment specifically on Windows 8 only. For this reason Microsoft has to change few things in the http.sys and IIS pipeline implementation. This is why IIS Express does not support WebSockets at the moment (not yet).

        <bindings>

          <netHttpBinding>

            <binding>

              <webSocketSettings connectionMode="Allowed" subProtocol="orders" />

              <security mode="None" />

            </binding>

          </netHttpBinding> 

        </bindings>

    As you see I used here NetHttpBinding.

    Client

    Now let’s implement the Client. Create the console or any other application and add the service reference to running service. This is automatically generated.

       <customBinding>
                    <binding name="NetHttpBinding_ISampleService">
                        <binaryMessageEncoding />
                        <httpTransport>
                            <webSocketSettings connectionMode="Allowed" subProtocol="orders" />
                        </httpTransport>
                    </binding>          

       </customBinding>

     

    Generated binding looks a strange, but it works. In fact NetHttpBinding is CustomBinding implementation which use http-transport and binary message encoder.

    You can do the same thing by using NetHttpBinding instead of CustomBinding:

        <bindings>
          <netHttpBinding>
            <binding>
              <webSocketSettings connectionMode="Allowed" subProtocol="orders" />
              <security mode="None" />
            </binding>
          </netHttpBinding>
        </bindings>

  • WpWidgetLibrary presentation

    After successful October meeting, Bihac .NET User group is organizing its 9th meeting at 17. Nov. 2011 at 17:00. The meeting wil take place at Technical faculty of the University of Bihac. This time the speaker will be daenet’s MVP Bahrudin Hrnjica who runs .NET User group Bihac in Bosnia. The presentation will talk about Windows Phone Mango and how to develop HTML5 mobile apps so called HTML5 Widgets.

    He will also presente WPWidgetLibrary open source framework for building HTML5 mobile apps on the Windows Phone Mango. The framework was announced on the MobilityDay conference in Zagreb, and after one month it is released as open source project on the Codeplex Microsoft open source portal.

    Here is a short description of the presentation which will Bahro give inn few days:

    Presentation Title: Windows Phone Mango and HTML5 app, Level: 300

    Description:

    Windows Phone 7.1 has internet browser, which is almost the same version used for IE9 desktop edition. This means the WP7+ is able to render HTML5 content. Usually Widows Phone is executing the HTML5 application which is hosted on some web server, and it is not a big deal to open it in online mode. If you like to open HTML App in offline mode you will have a little problem. Currently there is no way for WebBrowserControl in WP 7.1 mango to navigate to HTML file which is located somewhere in file system at the phone as this is supported by Android and iOS. This means you are constrains to develop clasic HTML5 Widget app on WP7. This presentation will try to show how to make HTML5 WP7.1 widget app by using WPWidgetLibrary – open source prject developed just to make HTML Wigdet as native WP7 app with ability to update and even publish HTML app on the WP7 marketplace. Presentation will also show how to use HTML5 tags like location and canvas in WP7, as well as how to incorporate jQuery and jQueryMobile as one of today the most popular tools for creating cross-platform mobile and tablet applications.

    image

    Please note that daenet will also give the AppFabric and WCF 4.5 presentation at the same date at Microsoft Bad Homburg in Germany.

  • METRO Catastrophic failure (Exception HRESULT: 0x8000FFFF (E_UNEXPECTED))

    Welcome back the the world of COM errors. If you get this one, it means you just have tried to to access one control from none-UI-thread.

    image

    Isn’t that one step back in the evolution of Microsoft development platform?

    Posted stu 10 2011, 11:11 by anonymous
    Filed under: ,
  • .NET User Group Vortrag–Microsoft Bad Homburg

    Als Abschluss des Jahres organisiert .NET User Group Frankfurt in Kooperation mit daenet bei Microsoft Bad Homburg einen Abend zum Thema:

    Die Software Entwicklung nach 2011”
    Was ist neu bei WCF 4.5, AppFabric & Co. in der Entwicklung von Enterprise, Web und Metro Anwendungen?

    In der letzten Dekade sind einige gute Technologien entstanden die uns helfen komplexere Lösungen einfacher und schneller zu implementieren. In dieser Dekade geht es genauso rasant weiter. Leider wird es immer schwieriger die richtige Technologie-Wahl zu treffen, weil es immer häufiger Ansätze gibt deren Lebenszyklus sehr kurz ist.
    An diesem Abend werden wir uns drei Stunden lang mit dem neuesten Themen beschäftigen, die die Architektur eines Systems festlegen und unterschiedlichsten Lösungen miteinander verbinden. Durch viele Demos zeigen wir welche neuen Möglichkeiten bieten WCF-WebApi, WebSockets, AppFabric ServiceBus Queues, Topics, Microsoft MiddleWare und Application Compostion für die Entwicklung von Anwendungen für Desktop, Web und Windows 8 Metro style Anwendungen.

    Es ist fuer jeden Profi-Entwickler etwas dabei. Microsoft sorgt wie immer fuer Getraenke.

    Achtung:
    Alle interessierten die ein Laptop dabei haben und 4GB frei, können die neueste verfügbare Dokumentation von Microsoft in Deutsch mitnehmen.


    Level 300

    Zielgruppe
    : Software Architekten, Entwickler und Business Analysten (Entscheider mit technischen Kenntnissen)

    Wann:
    11.Nov - 18.30 h

    Wo:
    Microsoft Bad Homburg – Germany
    http://www.microsoft.com/germany/unternehmen/informationen/gmbh_profil/niederlassungen/badhomburg.mspx

    Please note the session is for free, but the registration is mandatory.

    Posted stu 05 2011, 01:30 by anonymous
    Filed under: , ,
  • How to activate WCF in IIS8?

    When working with IIS8 and WCF 4.5 you will figure out that WCF does not work. (MIME type svc is not registered etc.). In this case aspnet_regiis tool will not help.
    To enable WCF go to Windows features and activate WCF 4.5 advanced Services:

    image

    Posted stu 02 2011, 12:24 by anonymous
    Filed under:
  • Flatten XML support in .NET 4.5 and WCF 4.5

    Few days ago I have described the need for flatten WSDL and published the tool which enables WCF developers to achieve this. Please note that Microsoft will include the similar feature in WCF 4.5 as a part of .NET 4.5 Framework.
    To enable flatten WSDL you do not have to do anything. Just build the service and open the Service URI. it is there. The feature is called “Single Service Description File”.

    Here is an example:

    image

    Notice ?wsdl in contrast to ?singleWsdl.

    The tool FlattenXml which I have posted here can be used to support this for all already existing WCF services.

    Posted stu 01 2011, 10:20 by anonymous
    Filed under:
Copyright of SQL/Developers Community
Powered by Community Server (Commercial Edition), by Telligent Systems