in

mscommunity.net

Interactive mscommunity.net online activities

DamirDobric

  • User Impersonation in WindowsForms and WPF

    Following example shows how to enforce interactive user in Windows Forms or WPF applications to become WindowsPrincipal, which can be read by Thread.CurrentPricipal:

      // This is identity of the user interactivelly logged on.
     
    WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

      // This would be required if you would logon user by username and password.
      // This example shows how to impersonate some other user than the interactive one.
      //
    WindowsImpersonationContext ctx = currentIdent.Impersonate();

      
      // This two calls make the all magic.

      WindowsPrincipal wP = new WindowsPrincipal(currentIdent);

     
    Thread.CurrentPrincipal = wP;

  • Troubleshooting DeepZoom

    My Browser crashes when opening DeepZoom image

    image

    One of following red-marked attributes can cause the browser to crash. TileSize has to have expected number. If images have been generated with TileSize=256
    and attribute in output.xml is set on 8 then the browser will crash.
    Attribute N must be uniquely specified.

    <Collection MaxLevel="8" TileSize="8" Format="jpg" NextItemId="16" ServerFormat="Default" xmlns="http://schemas.microsoft.com/deepzoom/2009">

    <I Id="9" N="" Source="output_images/Derventa.xml">
       <Size Width="2048" />
       <ViewPort Width="6" X="-3,5" Y="-8,5" />
    </I>
    . . .

     

    Some Images are not shown

    The attribute Height and Width has to be set or not specified. If specified then they have to have values.
    Following height means zero.

    <I Id="9" N=”1” Source="output_images/Derventa.xml">
       <Size Width="2048" Height="" />
       <ViewPort Width="6" Height="" X="-3,5" Y="-8,5" />
    </I>
    . . .

    Some images are shown as Black-Box

    The source file (i.e. output.xml) contains more than one image (element ‘I’) with the same identifier ‘N’.

    <I Id="9" N="9" Source="output_images/Derventa.xml">
       <Size Width="2048" Height="1360" />
       <ViewPort Width="6" Height="6" X="-3,5" Y="-8,5" />
    </I>
    <I Id="10" N="10" Source="output_images/Frankfurt.xml">
       <Size Width="2048" Height="1360" />
       <ViewPort Width="6" Height="6" X="-3,5" Y="-9,5" />
    </I>
    <I Id="11" N="9" Source="output_images/Prag.xml">
       <Size Width="2832" Height="2128" />
       <ViewPort Width="6" Height="6" X="-3,5" Y="-10,5" />
        </I>

    Unexpected images shown at specific zoom level

  • AppFabric Error: A base address with the uri scheme 'net.pipe' needs to be specified…

    When setting up your service, you may figure out, that service has not been properly started. To make sure, that this statement is true open the AppFabric event log and enable Operational logging. Clear all log entries and start the service.
    If the service is autstartable stop the pool before clearing of the event log. Now start the service and look for the error shown below:

    System.ServiceModel.ServiceActivationException: The service '/Services/RoutingService/ServiceManagement.svc' cannot be activated due to an exception during compilation. The exception message is: A base address with the uri scheme 'net.pipe' needs to be specified if using service management endpoint 'ServiceManagementNetPipeEndpoint'. Verify a base address exists on the site and the protocol is enabled on the application.. ---> System.Configuration.ConfigurationErrorsException: A base address with the uri scheme 'net.pipe' needs to be specified if using service management endpoint 'ServiceManagementNetPipeEndpoint'. Verify a base address exists on the site and the protocol is enabled on the application. at Microsoft.ApplicationServer.Hosting.Configuration.ServiceManagementConfiguration.LoadAndVerifyEndpoints(HashSet`1 enabledUriSchemes, HashSet`1 configuredEndpoints) at Microsoft.ApplicationServer.Hosting.Configuration.ServiceManagementConfiguration.GetEnabledEndpoints(Uri[] baseAddresses) at Microsoft.ApplicationServer.Hosting.Management.ServiceManagementFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath) 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) at Microsoft.ApplicationServer.Hosting.AutoStart.ApplicationServerAutoStartProvider.ActivateService(String virtualPath)


    The most important part of the messages is marked bold. To fix this you need to enable net.pipe protocol as shown at the next picture:

    clip_image002

    Note that http is scoped as default protocol, but it also has to be explicitly specified. If after this the error still appears, be sure that net.pipe protocol is enabled at the site binding in IIS manager. I figured out that this binding is sometimes not automatically enabled for site after installation of AppFabric.

     

    Hope this helps


    Damir

     

    image

    Posted ožu 04 2010, 11:38 by anonymous
    Filed under: ,
  • AppFabric BETA 2: The Platform for the Cloud Era

    If you are still asking yourself, what is the AppFabric, take a look on these few key features described below. After almost two years the Microsoft’s new product is getting to be released soon (Q3 2010). For now we are announcing the publicly available BETA 2 version, which is build on top of .NET 4.0. If you already have installed BETA 1 version please take a look on this post.

    Simplified Composite Apps (Built on top of .NET 4.0)

    Developers can simplify the development of composite applications with the pre-built application services in Windows Server AppFabric, used in conjunction with Visual Studio tools and .NET Framework capabilities (ASP.NET, WCF and WF). IT Pros can also simplify the deployment, monitoring, and management of composite applications with configuration and monitoring capabilities that are integrated with familiar tools (PowerShell, IIS Manager, and System Center).

    Faster Web Apps Made Easy (Known as Velocity)

    Windows Server AppFabric helps developers improve the speed and availability of web applications through distributed in-memory caching and replication technology that works with current ASP.NET applications.

    Enterprise Performance and Availability (Known as Dublin)

    An enterprise’s most important and demanding applications can achieve elastic scale, performance, availability, and reliability (benefits often associated with the cloud) with the help of Windows Server AppFabric. These and countless other benefits from an unparalleled partner ecosystem utilize familiar skills from the .NET Framework and Windows Server.

    Additional Resources:

    Gartner Research Report: Microsoft AppFabric: A Platform for the Cloud Era is Under Construction

    http://www.gartner.com/technology/media-products/reprints/microsoft/vol13/article6/article6.html

    Microsoft News Center feature story on Windows Server & Windows Azure platform AppFabric:

    http://www.microsoft.com/presspass/features/2009/nov09/11-17pdcappfabric.mspx

    Beta2 Blog Post on Windows Server Blog:

    http://blogs.technet.com/windowsserver/

    Additional information on Windows Server AppFabric:

    http://www.microsoft.com/windowsserver2008/en/us/app-main.aspx

    Information (including download link) for Windows Azure AppFabric:

    http://www.microsoft.com/windowsazure/appfabric/

  • The best of WCF 4.0 and WF 4.0

    At March 18th 2010 at Microsoft in Bad Homburg (Frankfurt area) I will give an overview of most important new features of upcoming WCF 4.0 and WF 4.0. The talk will be covered in context of .NET User Group Frankfurt am Main.
    Please feel invited all of you software architects and developers who leverage .NET technologies to build none trivial enterprise application for Windows platform.
    The session will take two hours at least of scheduled official part. After that we will step into none official part in legendary Bravery few hundred meters out of MS office. Please follow the official page of the .NET Group Frankfurt  for detailed schedule.

     

    Here is the agenda.

    •Simplified Configuration

    •File-Less Activation

    •Multiple Site Bindings

    •Standard Endpoints

    •Service Discovery

    •Routing Service

    •Workflow Services

    Optional (depending on time)

    •AppFabric

    •REST Improvements

    If anybody thinks, there would be something important I missed above, please let me know.

    Hope to see you there.

     

    Damir

  • How to enable multiple site bindings in WCF 4.0

    This post describes shortly how to enable multiple site bindings in WCF 4.0. Open IIS 7 Manager and create new site. Add two bindings to the site like shown in the picture below:

    image
    After that either configure your DNS or change host file %SYSTEM%\System32\drivers\etc\hosts like:


    127.0.0.1    sample1
    127.0.0.1    sample2

    When you now browse now for the service page by http://sample1/MyService.svc or http://sample2/MyService.svc you should get following error:

    This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'.
    Parameter name: item

    To make this working open the service’s config file and add following in the serviceModel element:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    That’s all…

    Posted vlj 28 2010, 01:00 by anonymous
    Filed under: ,
  • WCF 4.0 file-less activation error: ServiceHost only supports class service types.

    When working with WCF 4.0 and File-Less Service Activation you may get following error:

    ServiceHost only supports class service types.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: ServiceHost only supports class service types.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

     

    This scaring and possibly nothing saying error has very simple solution. I have following service:

    public class MyService : IMyService


    I used following configuration, which tryies to activate the service contract.

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
            <add relativeAddress="VirtualSvc.svc"
                
    service="Daenet.NetFx40.RoutingHost.IMyService" />
          </serviceActivations>
    </serviceHostingEnvironment>

     

    File Less service activation however requires the service class name and NOT the contract name. Here is the solution:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
            <add relativeAddress="VirtualSvc.svc"
                
    service="Daenet.NetFx40.RoutingHost.MyService" />
          </serviceActivations>
    </serviceHostingEnvironment>

    Posted vlj 25 2010, 11:12 by anonymous
    Filed under: ,
  • Standard Endpoints and MexBindings

    WCF 4.0 provides few so called standard endpoints:

    WorkflowControlEndpointElement
    ServiceMetadataEndpointElement
    AnnouncementEndpointElement
    UdpDiscoveryEndpointElement : DiscoveryEndpointElement
    DynamicEndpointElement

    They can be used to add some specific features to service. For example udpDiscoveryEndpoint enables add-hoc discovery of the service. This endpoint according to specification provides discovery of the service address. Unfortunately, this does not provide information about the binding and other service policies. To make this happen, there is mexEndpoint which enables metadata exchange. The mexEndpoint provides following bindings:

    MexHttpBindingElement, MexHttpsBindingElement, MexNamedPipeBindingElement and MexTcpBindingElement.

    Here is one example, which enables discovery of address (udpDiscovery) and whole binding with policies (mex):

    <services>

          <service name="Daenet.DNetfx40Discovery.SampleService">

            <endpoint name="Daenet.DNetfx40Discovery.ISampleService" binding="wsHttpBinding" contract="Daenet.DNetfx40Discovery.ISampleService" />     

     

           <endpoint kind="udpDiscoveryEndpoint"/>

     

           <endpoint kind = "mexEndpoint" address = "MEX" binding = "mexTcpBinding" />

          </service>

        </services>

  • Samples for WF 4.0 and WCF 4.0 Release Candidate

    Posted vlj 21 2010, 11:54 by anonymous
    Filed under:
  • Uninstalling of AppFabric Beta 1

    If you have installed the AppFabric beta 1, and want to install VS 2010 RC, note that you have to uninstall AppFabric BETA 1 before installing of VS RC bits.
    This is NOT documented in installation documentation of VS 2010 BETA 1. AppFabric BETA 1 is buld with dependency to .NET 40 BETA 1 which is build 4 v4.0.21006. The new version of .NET 4.0 is build v4.0.30128.

    When uninstalling AppFabric setup looks for the old version of .NET 40 BETA 1 which is renamed as old_4 v4.0.21006. The exact dependency of AppFabric Beta 1 is a dependency on the presence on these .NET Framework 4 configuration files:

    1. %SystemRoot%\Microsoft.NET\Framework[64]\v4.0.21006\config\machine.config
    2. %SystemRoot%\Microsoft.NET\Framework[64]\v4.0.21006\config\web.config

    To be sure that this cause the setup to fail uninstall process grab out the log file %systemroot%:\Windows\Logs\CBS\CBS.LOG
    You will find there following:

    Info: Loading configuration: C:\Windows\Microsoft.NET\Framework64\v4.0.21006\config\machine.config
    Error: Failed to load configuration.
    Error: Xml parse error 0x800c0006: The system cannot locate the object specified.


    Solution:
    To avoid this problem, uninstall AppFabric Beta 1 before uninstalling .NET Framework 4 v4.0.21006. Assuming that you are reading this you probably already uninstalled .NET BETA 1 :(

    So, to work around this problem if .NET Framework 4 v4.0.21006 was already removed, create the machine.config and web.config files in the old .NET Framework 4 location by copying from new .NET Framework 4 location. I simply have copied all existing config of v4.0.30128 to .4 v4.0.21006.
    After that unsinstall AppFabric and restart the machine.

    Then open applicationHost.config file of IIS 7 and remove following attrubutes from all apps which have it defined: "serviceAutoStartMode" and "previouslyEnabledProtocols
    These attributes are in ther if you have used “Always Running” feature of AppFabric.

    Thanks to AppFabric team which helped me solving this issue. Failed under.

  • First VS 2010 RC Patch for Brave Hearths

    If you are one of brave VS 2010 starters, you might notice that the VS IDE just diaper frequently  in front of your eyes.
    This happens if you are looking to critically focused on the screen or if you type something like MyClass<TypeHereAnything> or, or,..
    Anyhow, there is a help patch for this.

    :)

  • Visual Studio 2010 RC Setup does not start on Windows 7 - x64

    I tried to install Visual Studio Release Candidate 2010  on one one Windows 7 - 64 – Bit machines. Unfortunately the setup just does not start. If I try to start the same setup (to be sure that hash is correct) from other Win7 64-Bit machine it starts successfully.

    Note that my machine which cannot start the setup had previously installed VS 2010 Beta 2. I did my best to uninstall bunch of components in the right order. But, who knows.

    To workaround this problem I started the setup.exe in Setup folder and not setup.exe in the root of installation media (ISO, DVD or whatever you have). The setup.exe has been started elevated.

    This issue is documented at Microsoft connect site: https://connect.microsoft.com/VisualStudio/feedback/details/533209/visual-studio-2010-rc-setup-does-not-start-on-windows-7-x64

  • File-less activation of Routing Service

    while using File-Less activation feature to activate RoutingService you may experience an error.

    To make sure that RoutingService works at all, I added RoutingService.svc file which hosts RoutingService:

    <%@ ServiceHost Language="C#" Debug="true" Service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"%>


    When I open the page /RoutingService.svc the WSDL description is shown as expected.

    However, when I add file-less activation (se below), the error appears, when trying to open RoutingService.svc (delete this file when using file-less activation):

    Here is the configuration:

    <add relativeAddress="RoutingService2.svc" service="System.ServiceModel.Routing.RoutingService" />

    .. and these are errors:

    "The resource cannot be found" OR

    The type 'System.ServiceModel.Routing.RoutingService', provided as the Service attribute value in the ServiceHost directive could not be found.

    Following configuration solves the problem:

    <add relativeAddress="RoutingService.svc" service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

  • WinSpool.Drv SetPort function fails

    When calling SetPort function implemented in WinSpool.Drv within .NET, you may get following error:

    0x0000007C - The system call level is not correct.

    After intensive digging in internet I didn’t find anything related to this error. The problem is that obviously nobody has ever called it within .NET. This is reasonable, because this function is designed to be called within one port monitor, and port monitor is always written in C++ as user mode driver. Till now.

    The error above has no logical meaning. In my case indicates stack corruption, because .NET code didn’t marshal few parameters as expected. The reason for this is that all interop definitions of SetPort function, which you can found in internet  are just wrong. They probably have been generated automatically.

     

    The right definition is for sure:

    [DllImport(DllNames.WinSpool, CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern bool SetPort(

    [In, MarshalAs(UnmanagedType.LPWStr)] string pName,
    [In, MarshalAs(UnmanagedType.LPWStr)] string portName,
    uint dwLevel,
    IntPtr pData);

     

    And the ultimate call to SetPort looks like:

    IntPtr handle;
    PORT_INFO_3 pInf = new PORT_INFO_3();
    pInf.dwSeverity = WinSpooler.PORT_STATUS_TYPE_INFO;
    pInf.dwStatus = WinSpooler.PORT_STATUS_OFFLINE;
    pInf.pszStatus = null; // This works with OS Ver. >= 6

    uint level = 3;

    IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(pInf));

    Marshal.StructureToPtr(pInf, pData, true);

    bool res = WinSpooler.SetPort( null, "DOT4_002", level, pData);


     

  • Error while MergingDictionaries in Silverlight

    In my SIlverlight application I used following code to perform the merge of Resources which are stored in some dedicated assembly designed for this purpose. For this reason I used following code:

    ResourceDictionary dict = new ResourceDictionary();

    string src = “/MySilverlightControls;component/themes/MyDictionary.xaml”

    dict.Source = new Uri(src, UriKind.RelativeOrAbsolute);

    Application.Current.Resources.MergedDictionaries.Add(dict);


    This code usually works perfect. However sometimes it fails with following exception:

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    This nothing saying exception does not help and do not try do decrypt the hidden information. I figured out that following code does a bit better job.

    string src = “/MySilverlightControls;component/themes/MyDictionary.xaml”.

    StreamResourceInfo resourceInfo =
    Application.GetResourceStream(new Uri(src, UriKind.RelativeOrAbsolute));

    StreamReader resourceReader = new StreamReader(resourceInfo.Stream);

    string xaml = resourceReader.ReadToEnd();

    ResourceDictionary resourceTheme = XamlReader.Load(xaml) as ResourceDictionary;

    Application.Current.Resources.MergedDictionaries.Add(resourceTheme);

    When using this code you will get the real error description. In my case this was indication that I had some error in XAML, which designer didn’t discover:

    Invalid attribute value Daenet_Silverlight_Controls:WindowControl for property TargetType. [Line: 377 Position: 54]

    To solve this specifi problem I added missing declaration:

    xmlns:Daenet_Silverlight_Controls="clr-namespace:Daenet.Silverlight.Controls;assembly=Daenet.Silverlight"

    Posted sij 26 2010, 02:25 by anonymous
    Filed under:
More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems