An Avanade Blogging Community

Welcome to An Avanade Blogging Community Sign in | Join | Help
in Search

Johan's Avanade Blog

  • ADO.NET Data Services: how to invoke a WebGet service operation from a WebClient

    I have been working lately with ADO.NET Data Services, and I found several tutorials on how to create your first services and service operations.  But, then once I wanted to consume my service operations (WebGet), I was in the clouds...

    So, here are my 2 cents...

    First, here is the context of the service operation on the server:

    public class MyService : DataService<MyEntities>
        {
            // This method is called only once to initialize service-wide policies.
            public static void InitializeService(IDataServiceConfiguration config)
            {
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            }

            [WebGet]
            public IQueryable<Program> GetPrograms(int code, DateTime startDate, DateTime endDate)
            {
                return from program in this.CurrentDataSource.Program
                       where program.Code == code
                          && program.Date >= startDate.Date
                          && program.Date < endDate.Date
                       select program;
            }

    }

    Then, on the client I can invoke it as follow:

    public IList<Program> Retrieve(int code, DateTime startDate, DateTime endDate)
    {           
            var context = new MyService.MyEntities(<service url>);
            context.MergeOption = MergeOption.AppendOnly;
            var list = context.CreateQuery<Program>("GetPrograms")
                .AddQueryOption("code", code)
                .AddQueryOption("startDate", string.Format("datetime'{0:yyyy-MM-ddTHH:mm:ss}'", startDate))
                .AddQueryOption("endDate", string.Format("datetime'{0:yyyy-MM-ddTHH:mm:ss}'", endDate));

            return list.ToList();
    }

    Note that the parameters must be added inline to the CreateQuery method, and I had to use specific DateTime format for my parameters.

    Links

    Create Data-Centric Web Applications With Silverlight 2

    ADO.Net Data Services Part 1 - Building a Simple Web Data Service

    ADO.Net Data Services Part 2 - Using Service Operations with WebGet

    Service Operations in ADO.NET Data Services

  • Silverlight Debugger suddenly stopped working!

    I have been working on a Silverlight app (using VS2008 and Blend June Preview), and I first noticed that, sometimes, when I ran my app I did not have the latest code, so I stopped, rebuilt, and restarted the app and it usually worked.

    But this week, I have been blocked for an hour when my Debugger suddenly stopped working.  I thought the changes I made introduced strange behaviors causing the ASP.NET Development Server to stop.  Then, I realized that for some reasons my latest code was not cached anymore by IE!

    So, if your Silverlight app does not appear with your latest changes, or if your Debugger suddenly stops working, clear the "Temporary Internet Files" in IE ("Tools\Delete Browsing History..." menu).

    UPDATE

    Since this also happens when I update the structure of my solution (moving project in sub-folders, etc.), I also need to check the Properties of my Web Application.  The "Silverlight" CheckBox should be checked under Web / Debuggers.

    Links:

    Silverlight.net Forum - Debugger stopped working

    Silverlight.net Forum - aspx file not displaying the last .xap build

  • showModalDialog and PostBack

    Working on a MOSS component, I implemented a Modal Popup form including a SPGridView with Sorting an Filtering features.  unfortunately, I spent "huge" amount of time figuring-out how to make the grid working properly with its PostBack events.  The main issue was every javascript call resulted in the opening of a new form...

    I found a bunch of posts regarding this, and the main advice was to avoid using the showModalDialog for non-static content.  Just use the window.open()...

    I finally found this post.  The result was to add the following line to the <head> tag of my popup form:

    <base target="_self"/>

    With this all my javascript code and PostBack events work like a charm!

  • MenuItemTemplate and ClientOnClickUsingPostBackEvent

    I spend a fair amount of time before figuring out how to implement a Menu Item that would trigger a Post Back Event.  So, thanks to Powlo's blog, SharePoint Users Group and the MSDN forum.

    My overall goal was to implement a "Delete" MenuItemTemplate that triggers a Event on the server.  Here are the steps for my implementation:

    1. Implement the IPostBackEventHandler and its RaisePostBackEvent method.
    2. Add the MenuItemTemplate as follow in the aspx file:

    <SharePoint:MenuItemTemplate ID="DeletePortfolioMenuItem"
                                         runat="server"
                                         Text="Delete"
                                         Description="Delete this Portfolio"
                                         ImageUrl="/_layouts/images/delitem.gif"
                                         Sequence="2"
                                         ClientOnClickPostBackConfirmation="Are you sure you want to delete this item?"
                                         ClientOnClickUsingPostBackEvent="__page,%Name%" />

    Or in the codebehind by setting the ClientOnClickPostBackConfirmation and ClientOnClickUsingPostBackEvent in the CreateChildControls method:

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        DeletePortfolioMenuItem.ClientOnClickPostBackConfirmation = "Are you sure you want to delete this item?";
        DeletePortfolioMenuItem.ClientOnClickUsingPostBackEvent = "__page,%Name%";
    }

    The %Name% parameter is used here as the TokenNameAndValueFields in the SPMenuField of the SPGridView.  Its value is passed to the Event Argument of the RaisePostBackEvent method.

    Note: The functionality can also be implemented with the ClientOnClickScript as follow:

    DeletePortfolioMenuItem.ClientOnClickScript = "if (confirm('Are you sure you want to delete this item?')) __doPostBack('" + this.UniqueID + "','%Name%')";

  • New MIME to host Silverlight 2 Beta 1

    Recently, I upgraded my personal blog that contains a little Silverlight animation from Silverlight Alpha 1.1 to Silverlight 2 Beta 1.  So, I basically recreated my Silverlight project to have a look at the new features.

    When came the moment to deploy this new version to my host, I had a surprise: the animation was totally blank! :(

    So, what?

    Silverlight 2 now packs all required resources into a .XAP file (this is already the case for .XPS files).  So, this new type has to be added to IIS as application/x-silverlight-app.

    Links:

    How to configure IIS 6.0 to host Silverlight 2

    Using Silverlight 2 on a production Web Server

    Technorati Tags: ,,,
  • SharePoint 2007 Workflow with InfoPath

    This subject has already been described and detailed for a long time, so, the intent of this post is not to add another implementation on the subject, but gives a checklist and shares few issues faced.

    This checklist has been done using the following tools:

    • MOSS 2007
    • Visual Studio 2005
    • InfoPath 2007

    Setup the Working Environment

    1. Open Visual Studio 2005 and create a SharePoint Server Sequential Workflow project.

    InfoPath Form

    2. Open InfoPath 2007 and create a new Design Form Template.

    3. Add controls and fields to the InfoPath form.

    4. Check the Compatibility of the form.

    5. Change the Security to "Domain".

    6. Save the InfoPath file and Publish the form to "DevelopmentFiles/FeatureFiles" folder in the Visual Studio 2005 project that was created in step# 1.

    7. Save the InfoPath form as Source File.

    Visual Studio Project

    8. Execute the xsd.exe tool on the newly created myschema.xsd source file:

    Example: xsd.exe myschema.xsd /c

    This will generate the class corresponding to the fields used in the InfoPath form.

    9. Copy and rename the myschema.cs to the Visual Studio project.

    10. Update feature.xml and workflow.xml using Snippets.

    11. Code your workflow activities.

    Deployment

    12. Open the Project Properties, click on Build Events and change "NODEPLOY" to "DEPLOY" in Post-build event command line

    13. Sign the assembly and install it to the GAC.

    From this point you should be able to access your Workflow from "Site Settings / Galleries / Workflows", and attach it to any List.

    If you need to access the Workflow from the SharePoint Designer few more steps are needed.

    Setup the Workflow for SharePoint Designer

    14. Add an action entry in the WSS.ACTIONS file located in the following path:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow 

    15. Add an authorizedType entry to the web.config file of the Web Application.

    Now, the Workflow action is accessible from the New Workflow menu option.

     

    Issues Faced

    • The main issue faced is whenever you have an error in your InfoPath form and you get "The form has been closed" in SharePoint, or whenever you want to update the InfoPath form, the easiest is to delete the InfoPath Template and re-create a new one.

    Links:

    SharePoint 2007 Workflow with Visual Studio 2005 + InfoPath 2007

    Deploying a custom MOSS 2007 workflow

  • Windows Vista SP1 and Windows Server 2008 set for Launch!

    Both versions will be available mid-March.

    After a little check on MSDN Subscriber, WS2008 x64 is already available for download!  The other versions are coming.  The good news is it already contains Hyper-V (other versions will be available Without Hyper-V).  After using the RC1 on my laptop for a couple of weeks, I can say that my short experience is really positive: it's a lot faster on my configuration with Hyper-V than my previous one with Vista x86 and Virtual PC, and that it has been really stable until now.  So, I am pretty eager to install the final version.

    For more details about the install, follow Bryant's post about switching his laptop to Windows Server 2008.

    Links:

    Windows Vista SP1 Set For Launch, Microsoft Says

    Windows Vista SP1 et Windows Server 2008 finalisés

This Blog

Post Calendar

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Syndication