in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

travanj 2010 - Posts

  • AppFabric and .NET Framework dependencies

    Requirements for the Windows Server AppFabric features are shown in the following table.
    An “X” indicates that the feature depends on specified .NET Framework version.

    Feature

    .NET Framework 4

    .NET Framework 3.5 SP1

    Hosting Services *

    X

     

    Hosting Administration *

    X

     

    Caching Service

    X

    Optional

    Cache Client **

    .NET Framework 4 or .NET Framework 3.5 SP1

    .NET Framework 3.5 SP1 or .NET Framework 4

    Cache Administration

     

    X

     

    Integrated Version of .NET Framework:

    Windows Vista SP2 and Windows Server 2008 SP2 integrates the version of the .NET Framework 3.0.

    Windows 7 and Windows Server 2008 R2 integrates the version of the .NET Framework is version 3.5.

    .NET Framework 4 is installed with Visual Studio 2010. It means it is currently NOT integrated in any Windows operative system.

     

    * The integrated version of the .NET Framework will also be enabled when these features (Hosting Services and Hosting Administration) are selected.

    ** Your .NET Framework version selection for the Cache Client will depend on the application that you are planning to host.

     

    To download the .NET Framework, see .NET Framework 3.5 SP1 and .NET Framework 4.

    clip_image001Note

    Caching Features do not require IIS (Internet Information Server)

    Posted tra 29 2010, 11:03 by anonymous
    Filed under: ,
  • How to change T4 POCO Templates of EF 4 for WCF?

    Thanks to .NET 3.5 SP1 one class does not require to have DataContract attribute to be serializable by WCF. This is fine, but when building real SOA applications, there are always something special you will need. Such special things could be manually changed in POCO templates.
    Very good description of using of POCO with EF 4 can be found in ADO.NET team blog.

    Because POCO Templates cannot manipulate everything I need related to WCF, I decided to slightly change generated templates. To be able to append Data Contract related attributes, I did following:

     

    1. First I added new namespace:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    using System.Runtime.Serialization;

     

    2. Then I added DataContract attribute on each POCO class:

    [DataContract(Namespace="http://daenet.eu")]
    <#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
    {
    <#
        region.Begin("Primitive Properties");

        foreach (EdmProperty edmProperty in entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity))
        {
            bool isForeignKey = entity.NavigationProperties.Any(np=>np.GetDependentProperties().Contains(edmProperty));
            bool isDefaultValueDefinedInModel = (edmProperty.DefaultValue != null);
            bool generateAutomaticProperty = false;

    #>

     

    3. Then I added DataMember attributte on each member:

    #>
    [DataMember(EmitDefaultValue=true)]
        <#=PropertyVirtualModifier(Accessibility.ForProperty(edmProperty))#> <#=code.Escape(edmProperty.TypeUsage)#> <#=code.Escape(edmProperty)#>
        {
    <#
            if (isForeignKey)
            {
    #>


    Note that all changes remains even after EDMX model is changed or updated.

  • UnauthorizedAccessException: Invalid cross-thread access.

    When working with WCF DataServices in Silverlight 3 your callback methods have been executed on the UI-thread.
    Here is one example which works in Silverlight 3.0.

     

       private void onOperationCompleted(IAsyncResult result)
      
    {
        
    DataServiceQuery<View> ctx = result.AsyncState as DataServiceQuery< View >;

         ViewData.Result = ctx.EndExecute(result);

       }


    When this is migrated to Silverlight 4.0 following exception is thrown:

    image

    The solution for this looks like:

      private void onOperationCompleted(IAsyncResult result)
     
    {
         Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
           
    DataServiceQuery<View> ctx = result.AsyncState as DataServiceQuery<View>;

           
    IEnumerable< View > stations = ctx.EndExecute(result);

           
    ViewData.Result = ctx.EndExecute(result);

         });
      }

    Posted tra 22 2010, 04:36 by anonymous
    Filed under: ,
  • Silverlight 4: InvalidOperationException (SecurityException) WCF DataServices

    When migrating Silverlight 3 Project to Silverlight 4 you might experience following exception:

    InvalidOperationException (InnerException: SecurityException)

    image

    This error occurs when the SIlverlight application has been downloaded from one site like

    http://host1/app/default.aspx

    and WCF DataService invokes operation from service which is hosted on another site like:

    http://host2/app/service.svc/

    To make this working you need to deploy clientaccesspolicy.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="SOAPAction">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

    This policy file works in Silverlight 3. However Silverlight 4 is more clever and obviously can differentiate between real SOAPAction header, which is not sent in a case of DataService. DataServices uses REST pattern and not SOAP.

    Here is the required change in the policy file:

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>
    Posted tra 22 2010, 02:57 by anonymous
    Filed under: ,
  • Error while converting of SIlverlight 3.0 Projects with WCF Proxies

    While converting of SIlverlight 3.0 applications to implemented in Visual Studio 2008 to Visual Studio 2010 (and Silverlight 4.0) you will experience few problems if your Silverlight project(s) use WCF.

    Error message will in this case look like:

    Error    1    YourType' is an ambiguous reference between ‘Namespace1.YourType’ and ‘Namespace2.YourType’

    This happen if the SIlverlight project contains WCF Web Service reference with option ”Reuse Types in other assemblies”. Somehow conversion wizard of VS2010 ignores this option and recreates all types.

    To solve the problem, click the proxy generated code node located under Service References in the project and select Configure Service Reference.

    image

    Ensure that Reuse Types is clicked and press ok. This will automatically remove double created references from generated code.

    image

  • My Windays Sessions 2010

  • Merging UML Diagrams in Visual Studio 2010

    When working with Visual Studio 2010 UML diagrams, sometimes you might want to reuse one diagram created in another solution. For example your colleague has build diagram D1 and you are working in solution which contains diagram D2. Now you want to import the diagram D1 from solution 1 in solution 2.

    Simple requirement isn't’ it?

    Here is how to do this:

    0. Make a copy of the model definition file.
    This file can be found in the folder ModelDefinition. In our case this would be Solution2.uml, because we are importing D1 from Solution 1 in the solution 2.

    1. Add the UML diagram D1 from solution 1 to solution 2.
    Usually, diagrams are consisted of two files. For example D1.componentdiagram and D1.componentdiagram.layout.
    First one defines the model and second one is layout.

    2. Unload the model project, right mouse click on model project file and choose edit.
    This will open the project file as XML.
    Lookup the component D1 (in the picture below UMLComponentDiagram1).

    image

    The arrow shows the line which you have to insert, because this line does not exist after adding of these two file in the project.

    4. The last step is the most complicate one. You should manually merge files Solution1.uml and Solution2.uml.
    Following picture shows how to do that. Just copy all elements from solution 1 marked as green and paste them at corresponding position in the solution 2. All other elements (gray) can remain, because they are same across all solutions (at least at this moment).
    image 

    Hope this helps

    Visit www.daneet.de

  • Agenda for Windays 2010

    Unfortunately my definitive agenda for WinDays this year looks like:

    image

    PS: “Annulliert” means CANCELED!

  • Windays Flight Canceled

    Unfortunately, my flight like many others have been canceled today morning and I will not be able to attend WinDays.
    I’m very sorry for all of you guys who scheduled to attend my WCF, WF and AppFabric sessions.
    If any of you has any question related to content, please do not hesitate to contact me.

    This was the agenda for WCF and WF/AppFabric respectively:

    image

    image

     

    Sorry :(

    Damir

  • Silverlight WCF client error

    Error:

    The underlying channel factory could not be created because no binding information was found in the configuration file for endpoint with name '*'.  Please check the endpoint configuration section with name '*' to ensure that binding information is present and correct.

    Solution

    This error simply means: “The binding configured in one endpoint cannot be found”. For example bindingConfiguration is set on ‘ABC’, but the binding with ‘ABC’ name cannot be found.

  • Loading of Workflows

    In this post I will describe how to deal with different types of workflows.
    When loading workflows you may decide between :

    1. Loading of compiled activities
    2. Loading of activities from file

    By each of these two cases you have to consider two additional cases:

    a) Loading of Workflow
    b) Loading of Workflow Service

    Loading of Compiled Workflow

    Notice that the workflow is referenced as a type SimpleSequence.

    image

    Workflow is embedded in assembly as a type and as XAML resource.


    image

    Loading of Workflow from file

    Following example shows how to load workflow from file. Notice that there is no referenced SimpleSequence type anywhere in the code.
    This is important, because such workflows are not embedded in assemblies and cannot be referenced.

    image

    Loading of compiled Workflow Service

    I will not consider this case, because .NET 4.0 targets declarative service only. So, services are described in XAMLX-files and can be loaded from any store.

    Loading of Workflow Service from file

    Notice that the workflow SimpleSequence type is not used anywhere in the code.
    This is important, because such workflows are not embedded in assemblies and cannot be referenced.

    image

    The workflow SImpleSequence.xamlx is neither embedded in assembly or contained as resource. Notice also that assembly may contain other activities
    which are implemented as code and not in XAML. In this case it is TraceActivity.


    image

  • How to create OWA-Uri from ItemType.ItemId?

    When working with Exchange Web Service at some point of time you will want to create the OWA-URI.
    The Owa URI looks like: https://mail/owa/?ae=Item&a=Open&t=IPM.Note&id=RgAAAABew%2fP9Bu7QQo5izbUHshDuBwDeveWKhQQ4TbYfz8fgH%2b6TBVLgtiPtAADeveWKhQQ4TbYfz8fgH%2b6TBVLgtiYuAAAJ

    The crucial thing in this example is using of the item id property “id=..”
    Following code snippet shows how to create it:


    private
    static string createOwaId(ItemType exchMail)
    {

                string owaUri;

                byte[] itemBinId = System.Convert.FromBase64String(exchMail.ItemId.Id);

                byte[] owaBinUri = new byte[72];

                owaBinUri[0] = 70;

                Array.Copy(itemBinId, 27, owaBinUri, 1, 70);

                owaBinUri[owaBinUri.Length - 1] = 9 //(means message type);

                owaUri = Convert.ToBase64String(owaBinUri);

                owaUri = System.Web.HttpUtility.UrlEncode(owaUri);

                return owaUri;

    }

     
    This example can be useful if you want to create OWA-uri of some other types.
    Hope this helps you. If you want to help me please don't’ ask me how I have found the number 70 and 27 :)


  • Reading of Mails by using of Exchange Web Service

    Because I had several issues by implementing of this very simple requirement, I decided to describe it here for documentation purposes.

    Following code is used to retrieve mails form specific mail box.


            /// <summary>
            /// Retrieves the mails from mail box.
            /// </summary>
            /// <param name="startIndex">Firts mail to retrieve.</param>
            /// <param name="maxItems"></param>
            /// <param name="nextItem"></param>
            /// <returns></returns>
            public List<ItemType> GetItems(int startIndex, int maxItems, out int nextItem)
            {  
                //
                // Here we setup the paging
                IndexedPageViewType pagedView = new IndexedPageViewType();
                pagedView.BasePoint = IndexBasePointType.Beginning;
                pagedView.MaxEntriesReturned = maxItems;
                pagedView.MaxEntriesReturnedSpecified = true;
                pagedView.Offset = startIndex;

                //
                // Here we decide to read inbox.
                DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
                inbox.Id = DistinguishedFolderIdNameType.inbox;
              
                //
                // We want to retrieve mails with more or less all properties
                FindItemType findReq = new FindItemType();
                findReq.ItemShape = new ItemResponseShapeType();
                findReq.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
               
                // Retrieve by using of paging.
                findReq.Item = pagedView;

                // Retrieve the inbox items
                findReq.ParentFolderIds = new BaseFolderIdType[] { inbox };
                findReq.Traversal = ItemQueryTraversalType.Shallow;

                // Send request
                FindItemResponseType response = this.serviceProxy.FindItem(findReq);

                FindItemResponseMessageType responseMessage =
                response.ResponseMessages.Items[0] as FindItemResponseMessageType;

                if (responseMessage.ResponseCode != ResponseCodeType.NoError)
                {
                    throw new Exception(responseMessage.MessageText);
                }
                else
                {
                    //
                    // Here we read mails.
                    //

                    nextItem = responseMessage.RootFolder.IncludesLastItemInRange ? -1 :
                    responseMessage.RootFolder.IndexedPagingOffset;

                    ArrayOfRealItemsType items = responseMessage.RootFolder.Item as
                    ArrayOfRealItemsType
    ;
                    if (items.Items == null)
                    {
                        return new List<ItemType>();
                    }

                    List<ItemType> mailList = new List<ItemType>(items.Items.Length);

                    foreach (ItemType item in items.Items)
                    {
                        mailList.Add(item);
                    }

                    return mailList;
                }
            }
               


    If you want to retrieve mails from mailbox of an user in context of that user use following code to create service binding [ASMX (not WCF) service proxy]:

    private ExchangeServiceBinding serviceProxy = new ExchangeServiceBinding();

    this.credentials = new NetworkCredential(“userName@domainname”, “pwd”);

    this.serviceProxy.Url = “http://exchangehost/EWS/Exchange.asmx";

    this.serviceProxy.Credentials = this.credentials;    

    GetItems(). . .       

    However if you want to read mails of some user in context of some other user (i.e. administrator reads mails from one user), the you will get following error if you use proxy create as shown above:

    ”The server to which the application is connected cannot impersonate the requested user due to insufficient permission.”

    To make this working execute following power shell scripts, which will

    Get-ExchangeServer | Where {$_.ServerRole -match "ClientAccess"} | Add-ADPermission -User "User Name" -ExtendedRights ms-Exch-EPI-Impersonation -InheritanceType None


    Get-MailboxDatabase | Add-ADPermission -User "Administrator" -ExtendedRights ms-Exch-EPI-May-Impersonate -InheritanceType All

    These scripts set up ms-Exch-EPI-Impersonation and ms-Exch-EPI-May-Impersonate for all users with client access permission on that Exchange Server.

    After that, proxy has to be created as follows:


    this
    .credentials = new NetworkCredential(Administrator@domain, "pwd");
    this.serviceProxy.Url = ServiceUrl;
    this.serviceProxy.Credentials = this.credentials;

    ExchangeImpersonationType exExchangeImpersonation = new ExchangeImpersonationType();
    ConnectingSIDType csConnectingSid = new ConnectingSIDType();
    csConnectingSid.PrimarySmtpAddress = “userX@domain”;
    exExchangeImpersonation.ConnectingSID = csConnectingSid;
    this.serviceProxy.ExchangeImpersonation = exExchangeImpersonation;


    GetItems(). . .

    This code impersonate reads mailbox of user ‘userX‘ in contyext of user ‘Administrator’.





     


Copyright of SQL/Developers Community
Powered by Community Server (Commercial Edition), by Telligent Systems