locked
Trace OData client request URIs on WP7 RRS feed

  • Question

  • In my WP7 app, I'd like to trace the URIs of all OData requests. The WritingRequest and SendingRequest events of DataServiceContext looked promising, but neither of those have properties that contain the request URI (directly or indirectly).

    Is there some other object/method/event I can use to trace the URI of OData client requests on Windows Phone?

    Monday, July 2, 2012 10:48 PM

All replies

  • DataServiceContext. SendingRequest will work for you , code sample is below , You can check out my code samplehere  for one click experience of the same.

    If you are using Client Library 5.0 then please use SendingRequest2 

    namespace WCF.DataService.ClientLibSamples
    {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Data.Services.Client;
       
        using System.Diagnostics;
        using DSClintLibSampleUI.ServiceReference1;
        using DSClintLibSampleUI;
    
    
        /// <summary>
        /// TODO: Update summary.
        /// </summary>
        public partial class DataServiceContextAdvance: SampleBase
        {
            /// <summary>
            /// Demonstrate how to use DataServiceConext.SendingRequest for request logging purpose.
            /// </summary>
            public static void DataServiceContext_SendingRequest_Event()
            {
                if (GlobalSettings.JumpToDebugger) Debugger.Break();
    
                //Create an entity context 
                NORTHWNDEntities1 context = new NORTHWNDEntities1(new Uri(GlobalSettings.ServiceURI));
                
                //Register the event
                context.SendingRequest += new EventHandler<SendingRequestEventArgs>(context_SendingRequest);
                //Create a Linq query 
                var order = from o in context.Products
                            where o.ProductName.StartsWith("Ch")
                            select o;
    
                //Print Result 
               
                foreach (var item in order)
                {
                    OutputWriter.WriteLine(string.Format("Found Product ID={0}, Name={1} with product name starting with 'Ch'", item.ProductID, item.ProductName));
                }
            }
    
           
            static void context_SendingRequest(object sender, SendingRequestEventArgs e)
            {
                if (GlobalSettings.JumpToDebugger) Debugger.Break();
    
                string requestURI = e.Request.RequestUri.AbsoluteUri;
                OutputWriter.WriteLine("Requested URL:{0}", requestURI);
            }
        }
    }
    

    Tuesday, July 3, 2012 8:37 AM
  • Thanks, but your code will not work for me since I am developing on Windows Phone (Mango). As I mentioned in my post, the WP7 version of SendingRequestEventArgs does not have a Request property. Neither does ReadingWritingHttpMessageEventArgs.
    Tuesday, July 3, 2012 4:53 PM
  • ya , looks i missed it , In Desktop version there is no other extensibility point that can do this job so I doubt for WP7 libs (but confident as never worked on) may be someone else can help, 

    However if nothing works and you need this only for development and testing purpose then you can take advantage of client side HTTP proxy that can do the job of tracing url request.

    Wednesday, July 4, 2012 5:44 AM
  • I need to trace the URIs in circumstances where a web proxy (e.g., Fiddler) is not an option.
    Thursday, July 5, 2012 5:52 PM
  • I am not a mobile developer but for desktop I  have used proxy HTTP proxy like CCProxy that generates trace log for urls being requested , may be you can find similar solution for mobile 

    I one of my testing project I installed CCProxy On my desktop then connected the device with desktop and configured to you my system Proxy (CCProxy installed on desktop) for internet access. And i was able to generate trace

    May be it can help you 

    Friday, July 6, 2012 2:00 PM