in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

srpanj 2010 - Posts

  • Error by hosting of Win Azure Service Bus service in IIS

    When hosting WCF Services based on Microsoft Windows Azure Service Bus technology in Internet Information Server you will need to set the absolute address of service (i.e.: sb://mynamespace.servicebuse.net). Additionally, if your service is defined with file-less activation you must not enable multiple site bindings:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
            <add relativeAddress="ExchoService.svc" 
                
    service="Microsoft.ServiceBus.Samples.EchoService, ServiceInIis,
                
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

     

         </serviceActivations>
    </serviceHostingEnvironment>

    The value of attribute multipleSiteBindings must be set on FALSE. Otherwise following exception will be thrown. The exception can be found in EventLog.

    WebHost failed to process a request.
    Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/62163723
    Exception: System.ServiceModel.ServiceActivationException: The service '/ServiceInIis/ExchoService.svc' cannot be activated due to an exception during compilation.  The exception message is: When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint '
    https://dobric.servicebus.windows.net/EchoService/'.. ---> System.InvalidOperationException: When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'https://dobric.servicebus.windows.net/EchoService/'.
       at System.ServiceModel.Activation.ApplyHostConfigurationBehavior.ThrowIfAbsolute(Uri uri)
       at System.ServiceModel.Activation.ApplyHostConfigurationBehavior.FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase service)
       at System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.ServiceHostBase.InitializeRuntime()
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       --- End of inner exception stack trace ---
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
    Process Name: w3wp
    Process ID: 5368

  • Preventing of Security Warnings in Outlook Part 2 of 2

    Since release of Outlook 2010, developers have no more possibility to use use CDO and related libraries. For long time, these libraries have been smart simplification of MAPI, which is known as very complex and developer unfriendly. More over since release of Exchange 2010, support for WebDav has also been deprecated.
    The new way of programming of server components is now Exchange Web Service EWS and Outlook Object Model (the same name as in past) which is now quite simplified in Visual Studio 2010.

    Problems and one possible solution related to this feature are described in my previous post.

    In this post I will describe how to prevent security warning popups by using of a much smoother way.
    Before one do this, be sure, that I recommend it for advanced users only, because changes described in this post will allow potential viruses to access you private data in the address book!!!

    1. Go to Outlook Options
    image

    2. Select Customize Ribbon and add Developer Command Item in ribbon.

    image

    3. Select Developer Command Item and click “Macro Security”

    image

    4. Select “Programmatic Access” and choose “Never warn me about …”

    image

  • Preventing of Security Warnings in Outlook

    Since release of Outlook 2010, developers have no more possibility to use use CDO and related libraries. For long time, these libraries have been smart simplification of MAPI, which is known as very complex and developer unfriendly. More over since release of Exchange 2010, support for WebDav has also been deprecated.
    The new way of programming of server components is now Exchange Web Service EWS and Outlook Object Model (the same name as in past) which is now quite simplified in Visual Studio 2010.

    Unfortunately, when programming against this model you might notice security alerts (warnings) in form of popup window, when your code is trying to access protected objects like email address of one user.

    Here is one example:



    This is a good security model, but not really good development practice. The problem is that disabling of this protection seems to be very complex task described in many, many posts and articles in internet.
    Here are just few examples:http://www.outlookcode.com/article.aspx?id=52http://www.add-in-express.com/outlook-security/, http://msdn.microsoft.com/en-us/library/aa209964(office.11).aspx, http://technet.microsoft.com/de-de/library/ff657852.aspx

    The good thing is that Microsoft since Outlook 2007 provides one very simple solution for this. You do not need to use neither group policy or security templates. All you need is Vista or Windows 7 and one functioning Virus Scanner.

    New security model in Outlook 2007 and 2010 takes advantage of the status of antivirus software installed on a machine where you component is running. This change represents a major departure from the way the Object Model Guard worked in the past. If Outlook is able to detect that antivirus software is running with an acceptable status, Outlook disables security warnings for the user.

    More about this here: http://msdn.microsoft.com/en-us/bb226709(office.12).aspx

    When virus scanner reports acceptable status, you can notice that with marked icon below and can be checked by (Windows Security Centar API)

    image
    It is important, that hen Outlook is not running and your application creates the Outlook Application Object in background following icon appears:

    image

    Which means:

    image

    Here is a set of possible actions hen you click on icon:

    image

    Conclusion: To prevent Outlook of showing of security warnings install and run properly some virus scanner.

  • How to create and mount virtual drive?

    In this post I will chow how to create and mount a virtual drive. Virtual drive is a file Virtual Hard Drive. That means you can use it as any other NTF drive within System.IO namespace. In some scenarios it can be very helpful to write data to virtual drive and then to do something with the VHD drive. For example, when working with Windows Azure you can mount to this drive, write to it (by using System.IO namespace) and finally download a copy of that file (disc) for analyzing purposes.

    Interesting in this scenario is that the data in this drive is in fact Windows Azure blob storage data, which can also be accessed by standard blob storage API.

    Create Disk and Attach
    Save following script in some file like creatediskscript.txt. This will create the fixed disk of 50 MB, formatted as NTFS and mount it as drive V.

    create vdisk file="c:\temp\mydrive.vhd" maximum=50 type=fixed
    select vdisk file="c:\temp\mydrive.vhd"
    attach vdisk
    create partition primary
    assign letter=v
    format fs=ntfs label=vhd quick
    exit

    Open a command line console and execute the script:

    diskpart /s c:\temp\discscript.txt

    after executing of the script you will experience well known dialog, which is initiated by Virtual Disk Service:

    image

    After that you can use the disk as any other drive. Finally to disconnect do following:

    image

    Attach to Disk
    Following script shows how to attach to an existing disk:

    select vdisk file="c:\temp\mydrive.vhd"
    attach vdisk
    exit

    Detach Disk

    select vdisk file="c:\temp\mydrive.vhd"
    detach vdisk
    exit

  • Encryption with Key Container

    When encrypting some data in your application, you can use various already proven algorithms, which are integrated in .NET.
    However, one thing remains mostly unclear. When talking about encryption most people focus on algorithms. This is reasonable, but one algorithm is at least secure as the key is secured.
    In other words, if you have strong key and best algorithm in universe, but your key is insecurely stored, all is unsecured.

    For this reason I post very short sample, which shows how easy key store can be incorporated in your application. If you try in this example to change CspParameters all will work fine as long both methods EncryptByContainer and DecryptByContainer
    use exactly the same settings.


            private static void Start()
            {
                byte[] decryptedData = EncryptByContainer("Daenet is award winner");
               
                string txt = DecryptByContainer(decryptedData);
            }

            private static byte[] EncryptByContainer(string txt)
            {
                byte[] binData = Encoding.Unicode.GetBytes(txt);

                CspParameters cspPrms = new CspParameters();
                cspPrms.Flags = CspProviderFlags.UseMachineKeyStore;
                cspPrms.KeyContainerName = "TestKey";
               
                RSACryptoServiceProvider rsaProv = new RSACryptoServiceProvider(cspPrms);

                byte[] encyptedData = rsaProv.Encrypt(binData, true);

                return encyptedData;
            }

            private static string DecryptByContainer(byte[] encryptedData)
            {
                string txt;
             
                CspParameters cspPrms = new CspParameters();
                cspPrms.Flags = CspProviderFlags.UseMachineKeyStore;
                cspPrms.KeyContainerName = "TestKey";

                RSACryptoServiceProvider rsaProv = new RSACryptoServiceProvider(cspPrms);

                byte[] decrypedData = rsaProv.Decrypt(encryptedData, true);

                txt = Encoding.Unicode.GetString(decrypedData);

                return txt;
            }



  • ICE Platz Reservierung

    When travelling by train in Germany, I never know what seat I should book. So I decided this time to write down all required information.
    Here it is in German:

    Alle ICE Züge in Frankfurt sind in Fahrtrichtung von 1 bis N eingeordnet. D.H. der erste Wagen ist Nummer „1“, ist an Lock angehängt und ist meistens im Bereich „F“ positioniert.
    Der letzte Wagen ist in der Regel im Bereich „A“ positioniert. Bereich „A“ ist gleich am Anfang von Gleis (schnell zu erreichen) und Bereich „F“ am weitesten vom Gleis-Eingang entfernt (ca. 100 m).
    Die Wägen Klasse „1“ sind meistens im Bereich „A“ positioniert, dann kommt Bord Restorant und dann die Wägen Klasse „2“.
    Die Wägen Klasse „2“ fangen meistens mit 6 oder 7 an. Somit ist Bord Restorant Wagen meistens Nummer 5.

    Die Sitznummern im Wägen fangen mit 10 an und enden mit 80. Die ersten Nummer (also ab 10) sind in der Fahrtrichtung positioniert und die letzteren (also 80) von Lock weiter entfernt.
    Wenn Sie z.B, an der Tür am Anfang des Wagens in der Fahrtrichtung sitzen möchten, nehmen Sie die kleinsten Nummer 10-18. Dies Plätze sind alle entgegen der Fahrtrichtung positioniert
    (Sie fahren Rückwerts).

    Dann kommen die Plätze 23-28. Das sind die Tischplätze mit Stromanschluss. Für Laptops über 19‘‘ nicht wirklich geeignet. Die Leistung der Steckdose ist mir nicht bekannt. Sicher ist es, dass die 140 VA vertragen können.

    Die Tischplätze mit ungerade Nummer (25, 27, 21 und 23) sind entgegen der Fahrtrichtung. Die restlichen (22, 24, 26 und 28) sind in der Fahrtrichtung.

    Manchmal fahren die Züge in umgekehrter Reihenfolge. Dann ist natürlich alles verkehrt rum.

  • Error while installing outlook 2010 or CDO

    While installing some of Outlook components you may get following error:

    “Outlook 2010 may not be installed with a newer version of outlook”

    This error is caused by at least two possible reasons:

    1. There is already an Outlook 2010 installed on the machine and you are trying to install CDO library.
    2. There is already CDO (Collaboration Data Objects) library installed on the machine and you are trying to install Outlook 2010.

    What ever the reason is, remove previously installed components. The error is caused by side by side installation of CDO and Outlook 2010, which is NOT supported. CDO and related components are deprecated since Outlook 14 (2010).

     

    If you need to implement client based peace of code, you will have to use either MAPI or Outlook Object model as an Add-In or any kind of other application type.

  • FileNotFoundException, invalid ImpersonationLevel & Co.

    When working with AppFabric Caching features in an application (i.E. web service) hosted in IIS, you might experience following problem:

    === Pre-bind state information ===
    LOG: User = Unknown
    LOG: DisplayName = Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    (Fully-specified)
    LOG: Appbase = file:///D:/Tfs/ble/bla...
    LOG: Initial PrivatePath = D:\Tfs\ble\bla\bin
    Calling assembly : Jettware.System, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: D:\Tfs\ble\bla\web.config
    LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

    Depending on the place in code where Caching objects are initialized, the same error can be detected as next snippet shows too:

    FileNotFoundException:

    C:\Windows\assembly\GAC_MSIL\Microsoft.ApplicationServer.Caching.Client\1.0.0.0__31bf3856ad364e35\Microsoft.ApplicationServer.Caching.Client.dll

    Note that we have experienced the same problem with other libraries like Entity Framework. Anyhow there are several error messages which in fact indicates the same problem.
    My favorite one is: “".. ‘localhost’ cannot be resolved”. This error would get the caller of web service operation which fails with one of exceptions shown above.

    I always say “If you don’t know what is the problem, then the answer could be probably Kerberos.” Fortunately this time is not Kerberos in play :). It is much wars. :(

    The real problem is however security or more precisely impersonation level. This can happen when your service allows or requires the impersonation and when impersonation is done.

    For example, the exception can be caused by this code:

    using (((WindowsIdentity)Thread.CurrentPrincipal.Identity).Impersonate())
    {
          new DataCacheFactory();
    }

    This code will enforce the thread to impersonate the thread user as a caller of an external service. In this case DistributedCacheService. Because the impersonated user is possibly not permitted to instantiate the cache object (do not ask me why), on eof exceptions shown above will be thrown.

    Here the workaround to solve this problem:

     

    The new DataCacheFactory has to be called not impersonated (with pool user) once and anywhere in the application domain. After this all other calls to all cache class constructors will work.

    public class myclass
    {
            static myclass()
            {
                 DataCacheFactory f = new DataCacheFactory();

            }

    public void myMethod
    {
        using (((WindowsIdentity)Thread.CurrentPrincipal.Identity).Impersonate())
       {
           new DataCacheFactory();
       }
    }

    }

  • Workflow Persistence Tables

    When digging in persistence table I often use few useful queries, which gives me all required information I mostly need.
    Without of commenting too much, I will just post queries and results here for documentation purposes.

    SELECT * FROM [RootPersistenceDb].[System.Activities.DurableInstancing].[RunnableInstancesTable]

    SELECT * FROM [RootPersistenceDb].[System.Activities.DurableInstancing].[LockOwnersTable]

    SELECT * FROM [RootPersistenceDb].[System.Activities.DurableInstancing].[KeysTable]

    SELECT * from    [RootPersistenceDb].[System.Activities.DurableInstancing].[InstancesTable]

     

    If the instance is shown in RunnableInstancesTable, it means it is persisted (and unlocked) and it can be loaded.

    image

    If the same instance is running it is not possible to load it again by some other host. In this case RunnableInstancesTable does not contain this instance.

    image

    Posted srp 09 2010, 10:30 by anonymous
    Filed under:
Copyright of SQL/Developers Community
Powered by Community Server (Commercial Edition), by Telligent Systems