in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

svibanj 2010 - Posts

  • Exchange Web Service folder search

    Exchange Web Service EWS provides for sure powerful search mechanism. Unfortinatelly building EWS consumers is not very trivial task, because query implementation is not well documented and it is not very intuitive. That means you need too much time to build simpe things. One good example is following code snippet. It shows one method which search for all folders (up to 1024 –defined by  MaxEntriesReturned and Denominator) with specified name (folderName).
    For example if you want to search by containment string of exact match you will need to use property ContainmetMode.
    Etc., etc. All other pieces of code whown below do not contain very much information (entropy low).

    How this helps anyone to save a few hours.

       private static List<BaseFolderType> findFolder(ExchangeServiceBinding serviceProxy,
                           string folderName, bool exactMatch)
            {
                // Create the request and specify the traversal type.
               
                FindFolderType findFolderRequest = new FindFolderType();
                findFolderRequest.Traversal = FolderQueryTraversalType.Deep;

                // Define the properties to be returned in the response.
                FolderResponseShapeType responseShape = new FolderResponseShapeType();
                responseShape.BaseShape = DefaultShapeNamesType.Default;
                findFolderRequest.FolderShape = responseShape;

                // Identify which folders to search.
                DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
                folderIDArray[0] = new DistinguishedFolderIdType();
                folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;

                // In what folders to search
                findFolderRequest.ParentFolderIds = folderIDArray;

                // SEarch by folder name.
                RestrictionType restriction = new RestrictionType();
                PathToUnindexedFieldType restrict = new PathToUnindexedFieldType();
                restrict.FieldURI = UnindexedFieldURIType.folderDisplayName;
             
                // Build simple search operator
                ContainsExpressionType contains = new ContainsExpressionType();
                contains.ContainmentMode = exactMatch ? ContainmentModeType.FullString : ContainmentModeType.Substring;
                contains.ContainmentModeSpecified = true;
                contains.ContainmentComparison = ContainmentComparisonType.IgnoreCase;
                contains.ContainmentComparisonSpecified = true;
                contains.Item = restrict;
                contains.Constant = new ConstantValueType();
                contains.Constant.Value = folderName ;
                restriction.Item = contains;

                findFolderRequest.Restriction = restriction;

                // Define the paging scheme for the result set.
                FractionalPageViewType fpvt = new FractionalPageViewType();
                fpvt.MaxEntriesReturned = 1024;
                fpvt.MaxEntriesReturnedSpecified = true;
                fpvt.Numerator = 1; // Don’t try to find documentation for this
                fpvt.Denominator = 1024; // Don’t try to find documentation for this.
                findFolderRequest.Item = fpvt;

                // Send the request and get the response.
                FindFolderResponseType findFolderResponse = serviceProxy.FindFolder(findFolderRequest);

                // Get the response messages.
                ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items;

                List<BaseFolderType> result = new List<BaseFolderType>();
                foreach (ResponseMessageType rmt in rmta)
                {
                    FindFolderResponseMessageType ffrmt = (rmt as FindFolderResponseMessageType);

                    FindFolderParentType ffpt = ffrmt.RootFolder;
                    BaseFolderType[] folders = ffpt.Folders;

                    result.AddRange(folders);
                }

                return result;
            }

     

     

  • Silverlight and error HTTP/1.1 504

    When working with WCF in SIlverlight sometimes you  might get following error:

    The remote server returned an error: NotFound.

     

    at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
    at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

    After digging in Fiddler you will find following:

    HTTP/1.1 504 Fiddler - Receive Failure
    Content-Type: text/html
    Connection: close
    Timestamp: 11:16:16:9903

    ReadResponse() failed: The server did not return a response for this request.   


    Assuming that you like me do not have any glue about the problem, here is a short explanation.
    If There is an enum in your service contract which looks like: following sample, the error will appear..

    [DataContract(Namespace=Constants.EntityNamespace)]
       public enum TagStatus
       {
           [EnumMember]
           Active = 1,

           [EnumMember]
           Paused = 2
       }

    Believe or not, the problem is that the enum has to start with zero like shown below:

    [DataContract(Namespace=Constants.EntityNamespace)]
       public enum TagStatus
       {
           [EnumMember]
           Active = 0,

           [EnumMember]
           Paused = 1
       }

  • HttpNotificationChannel.Open() fails with ‘NotificationChannelOpenException’

    When trying to register the channel for notifications, you may notice that callback handler ‘ChannelUriUpdated’ is never invoked. If that happens register the callback ‘ExceptionOccurred’. This will give you a chance to receive the exception, which cases the channel to fails.
    Unfortunately exceptions are still not very useful, because they do not say too much.

    For example, I experienced ‘NotificationChannelOpenException’. It is more confusing the fact that this exception is not thrown in examples, which are provided by Microsoft. If you use exactly the same code, the channel registration will just fail after Open() is called. 
    So, the something has to be different ?!

    The solution is in WMAppManifest.xml file. This file is a part of the WP7 project:

    image

    Open that file and set the attribute Publisher to anything.

    image

  • Windows Server AppFabric Case Study on Windows 7 Series :)

    If you would be happy owner of Windows Phone you could download the demo app which plays the daenet and Jettaine CAse Study on Windows Mobile 7.

    Click here to play video or here to read about solution.

    image

  • Application Infrastructure Virtual Launch Event

     

    While you explore how to use the cloud in the long-term, find out how to harness the benefits of the cloud here and now. In this virtual event Microsoft shows how to:

    · Increase scale using commodity hardware.

    · Boost speed and availability of current web, composite, and line-of-business applications.

    · Build distributed applications spanning on-premises and cloud.

    · Simplify building and management of composite applications.

    · And much, much more!

    Enter Virtual Event: http://www.appinfrastructure.com/

    For this reason Jettainer and daenet recorded a video which describes one very sophisticated solution, which we build up in the last year. Because this SOA solution integrates a bunch of technologies like AppFabric, SQL Server, BizTalk Server, .NET 4.0, WCF 4.0, WF 4.0, SIlverlight 4.0 etc., Microsoft did a Video, which shows what is possible to do with right technologies and Agile approach in very short time. 

    Enjoy …

    image image

     

    Direct link to video: http://mediadl.microsoft.com/mediadl/www/V/virtualevents/asgtechnologies/1003706_Jettainer_500k.wmv

  • WCF 4.0 REST Samples (German)

    Die meisten REST Features von WCF konnte man bisher ausschließlich im WCF Starter Kit finden. Ab .NET 4.0 sind diese überwiegend zum festen Bestandteil von WCF 4.0 geworden. Um ein REST Service zu erstellen am einfachsten ist es im Visual Studio 2010 WCF Rest Template zu verwenden, das über Code Gallery sehr einfach und schnell installierbar ist.

    Ein REST-Service Projekt benötigt eine Global.Asax Datei aus ASP.NET, damit die RoutingTable für Service angelegt werden kann:
    RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));

    Die Registrierung oben definiert eine Route fuer Service1 mit gegebener HostFactory. Damit kann folgende Operation  

     

    [WebGet(UriTemplate = "")]
    public List<MyResource> GetCollection()


    über folgendes URI erreicht werden: http://host/service1

    Wenn eine Operation Eingabeparameter hat kann sie wie folgt definiert werden:

    [WebGet(UriTemplate = "{id}")]
    public MyResource Get(string id)


    Fuer id=123, wuerde man folgende URI wenden:

    http://host/service1/1231

    Etwas komplexer ist folgendes Beispiel mit zwei Argumenten:

    [WebGet(UriTemplate = "gettime/{zone}/{format}")]
    public DateTime GetTime(string zone, string format)


    Die URI für diese Operation lautet:
    http://host/service1/gettime/berlin/YYYYMMDD

    Mit verschiedenen URI-Templates kann man die Service Abfragen beliebig stylen. Am einfachsten ist es eine URI zu verwenden, die verschiedene HTTP-Methoden einsetzt. Zum Beispiel um die Ressource zu erzeugen definiert man Operaqtion Create.

    [WebInvoke(UriTemplate = "", Method = "POST")]
    public MyResource CreateResource(MyResource instance)

     

    Diese Operation wäre über URI http://host/service1 erreichbar. Allerdings HTTP Body müsste MyResource enthalten. Im JSON würde dies wie folgt aussehen:
    {"Id":2147483647,"StringValue":"String content"}

    Somit ist es möglich auch weiter HTTP Methoden wie PUT (für UpdateResource) oder DELETE (für DeleteResource) anzuwenden.

    Last, but not least WCF 4.0 REST bietet eine automatisch generierte Help-Page an. Diese ist unter folgender URI zu finden: http://host/service1/help
    Damit haben auch die REST-basierte Dienste eine mehr oder weniger ausführliche Beschreibung.

    Cheers

     

  • SIlverlight troubleshooting with different browsers

    When working with silver light and different browsers, you may experience that sometimes some Silverlight applications do not work or they are not shown in the browser at all. Then, let’ start.

    Internet Explorer

    If using Internet Explorer all of issues described below will always work.

    Coogle Chrome


    If using Google Chrome and Silverlight WebControl introduced in Silverlight 2, you will notice that the Silverlight control will not appear in Chrome when working with update panels.
    For this reason I rewrote that control. The code below gives you an idea how to do that.

      protected override void RenderContents(HtmlTextWriter output)
    {

                StringBuilder sb = new StringBuilder();

                sb.AppendLine(String.Format("<object data=\"data:application/x-silverlight-2\" type=\"application/x-silverlight-2\" id=\"{0}\" width=\"{1}px\" height=\"{2}px\" >", this.Id, this.Width, this.Height));

     

               sb.AppendLine(String.Format("<param name=\"source\" value=\"{0}\" />", this.Source));

     

               sb.AppendLine("<param name=\"onError\" value=\"onSilverlightError\" />");

                sb.AppendLine(String.Format("<param name=\"background\" value=\"{0}\" />", this.Background));

                sb.AppendLine(String.Format("<param name=\"minRuntimeVersion\" value=\"{0}\" />", MinimumVersion));

                sb.AppendLine("<param name=\"autoUpgrade\" value=\"true\" />");

     

               sb.AppendLine(String.Format("<param name=\"InitParams\" value=\"{0}\" />", m_InitParams));

                sb.AppendLine("</object>");

     

               output.Write(sb.ToString());

            }

    Please also note, that putting of this code inside of some JAVA function which will be executed automatically on loading of UpdatePanel will not work.

    Firefox

    My favorite issue in this context is Firefox. The code shown above will NOT work in firefox, because data propery is set on “data:application/x-silverlight-2”. The picture belove shows my fatal mistake:

    image

    The data property should be initialized on “data:application/x-silverlight-2,”.

     

    :)

  • Accessing of Rows in Silverlight DataGrid

    Imagine you want to enumerate (enlist) all rows (DataGridRow) of Silverlight Grid (DataGrid). By design this is not very simple tasks.
    For example, you want to do something like this:

                foreach (DataGridRow rowItem in grid.Rows)
                {
                       . . .
                 }

    This very important and very frequent requirement is just an issue. You will notice that this is almost impossible and will start to research in internet. Good luck. So, I decided to post the code of extension class which makes this possible:

                foreach (DataGridRow rowItem in grid.GetRows())
                {
                       . . .
                 }

    Here is the whole code:

        /// <summary>
        /// Extends the DataGrid.
        /// </summary>
        public static class DataGridExtensions
        {
            /// <summary>
            /// Gets the list of DataGridRow objects.
            /// </summary>
            /// <param name="grid">The grid wirhrows.</param>
            /// <returns>List of rows of the grid.</returns>
            public static ICollection<DataGridRow> GetRows(this DataGrid grid)
            {
                List<DataGridRow> rows = new List<DataGridRow>();

                foreach (var rowItem in grid.ItemsSource)
                {
                    // Ensures that all rows are loaded.
                    grid.ScrollIntoView(rowItem, grid.Columns.Last());

                    // Get the content of the cell.
                    FrameworkElement el = grid.Columns.Last().GetCellContent(rowItem);

                    // Retrieve the row which is parent of given element.
                    DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement);

                    // Sometimes some rows for some reason can be null.
                    if (row != null)
                        rows.Add(row);
                }

                return rows;
            }
        }


    This line I put here to measure how some interesting words can dramatically increase landing frequency of boring technical posts.

    Bayern Inter Football Soccer champions league  

    Please forgive me for this :)

    Posted svi 02 2010, 12:30 by anonymous
    Filed under:
  • Windows Azure Offers

    Offers for Windows Azure include offers for MSDN and Partners too. So I decided to provide few links to Azure-offerings, which I personally find very complicate. If anybody of Microsoft decision makers is reading this, here is one very simple example how Google does this.

    One of the first questions from most developers will be: What’s the cost? Sign up is free and so is running your app as long as stay under quotas 500MB of storage, 200 million megacycles/day of CPU, and 10GB of total bandwidth. Google estimates this means there will be no cost for up to approximately 5 million pageviews a month. Once this initial preview period is over Google will introduce a billing model for additional resources at competitive market prices.”
    (http://blog.programmableweb.com/2008/04/08/google-app-engine-your-apps-in-the-cloud/)

    Now, after you are done with this very simple Google offer read following Microsoft offer(s)…

    Windows Azure Platform Benefits for MSDN Subscribers

    The Windows Azure Platform is an internet-scale cloud computing and services platform hosted in Microsoft data centers. The platform provides a range of functionality to build applications from consumer web to enterprise scenarios. MSDN subscribers can take advantage of this platform at no extra charge to build and deploy their applications.

    Introductory 8-month Offer Available Today for 1264$ (only)
    http://msdn.microsoft.com/en-us/subscriptions/ee461076.aspx

    Windows Azure Platform Offers for Microsoft Partners

    This is a special offer for members of the Microsoft Partner Network that requires no minimum fee.  You pay only for what you use of compute hours, storage, data transfers, SQL Azure databases, Access Control transactions and Service Bus connections.

    https://partner.microsoft.com/40118760

     

    For all:


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

     

    Windows Azure Platform Offer Comparison Table

    http://www.microsoft.com/windowsazure/offers/popup.aspx?lang=en&locale=en-US&offer=COMPARE

     

    It might be that I didn’t invest enough time to understand all of these offers, but I feel confused. As developer I expected for developers free of charge with some limitations. Is that really the right way to help Microsoft partners and other developers to leverage the cloud platform?

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