none
Custom Binding with AJAX Enable WCF Web Service RRS feed

  • Question

  • Good Morning Folks,

     

    We have a requirement of creating AJAX Enable WCF web services for our mobile app project. We’ve a issues of web services performance and after a research I found that we can increase performance by including custom binding and applying few changes in web.config file because we’re using default settings for WCF web services only.

     

    I’m not sure whether changes I’ve applied to web.config file (attach with the response) is valid or not. I need some help to confirm my changes. Also, do I need to add web.config file on client side also. If so then, can you please provide client side web.config file.

     

    Is there anything more we can do to increase performance?

     

    Appreciate your help and support.

    <?xml version="1.0" encoding="utf-8"?>
    
    <configuration>
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <identity impersonate="false" />
        <webServices>
          <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
      </system.web>
    
      <system.serviceModel>
        <diagnostics performanceCounters="All"></diagnostics>
        <behaviors>
    
          <endpointBehaviors>
            <behavior name="MobileService.webHttpBehavior">
              <enableWebScript />
            </behavior>
          </endpointBehaviors>
          
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
    
              <!--Increase WCF Performance-->
              <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>      
    
            </behavior>
          </serviceBehaviors>     
        </behaviors>
        
        <!--Increase WCF Performance-->
        <bindings>
          <webHttpBinding>
            <binding name="webHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
              <readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
            </binding>
          </webHttpBinding> 
        </bindings>
    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    
        <services>
          <service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
            <endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" bindingConfiguration="webHttp" />        
          </service>
        </services>
    
      </system.serviceModel>
    
    </configuration>

    Tuesday, September 1, 2015 3:36 PM

Answers

  • Thanks for the response. I did go over the references you have suggested. But at this moment converting our current WCF will be a lot of work for us and still we are not sure whether it will increase the performance or not.

    I didn't say anything about a conversion. What I said was bury the WCF service behind the WebAPI controllers. If you have a Service Layer classlib project that consumes the WCF service, then the WebApi controller is making calls to the ServiceLayer that in turn is making calls to the WCF service with the WCF service as/is, and the WebAPI can use Jason and Ajax with the client.

    The Service Layer below  I use where the BLL and DAL are setting behind the WCF Web service, which you don't have to do it that way. The key is what is happening with the Service Layer.

    Where did I get the Service Layer concept?

    http://polymorphicpodcast.com/shows/mv-patterns/

    Now,  you don't have to use the Service.Instance, because of IoC frameworks like Unity, Castel Windsor and other to create an instance of the Service object.

    using System.Collections.Generic;
    using BLL.DTO;

    namespace Services.IServices
    {
        public interface IService1
        {
            List<DTOAuthor> GetAuthors();
            List<DTOAuthor> GetAuthorsWhere();
            List<DTOAuthor> SaveAuthors(List<DTOAuthor> authors);
            DTOPayroll GetPayRollByAuthorID(int id);
            void UpdatePayRollSalary(DTOPayroll pr);
            DTOPayroll AddPayRoll(DTOPayroll pr);
            void DeletePayRoll(DTOPayroll pr);
            DTOArticle GetArticleTop1();
            DTOArticle GetArticle(int id);
            List<DTOArticle> GetArticles();
            List<DTOArticle> SaveArticles(List<DTOArticle> articles);
            void DeleteArticle(DTOArticle srticle);
        }

    The Service Layer itself that allows me to decouple the frontend of ASP.NET UI using MVP, ASP.NET MVC UI,  Windows form UI using MVP and WPF MVVM UI. Each one of the frontend UI(s) are doing the same functionality. The Service Layer and out don't care what the client UI is about.

    The Service Layer classlib project that consumes the WCF Web service.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using BLL.DTO;
    using Services.IServices;

    namespace Services
    {
        public class TheService1 : IService1
        {
            private static readonly TheService1 mInstance = null;


            public static TheService1 Instance
            {
                get { return mInstance; }
            }

            static TheService1()
            {
                mInstance = new TheService1();
            }

            public List<DTOAuthor> GetAuthors()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.GetAuthors();
                    client.Close();


                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor()
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return authors;
            }
            public List<DTOAuthor> GetAuthorsWhere()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.GetAuthorsWhere();
                    client.Close();
                   authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return authors;
            }

            public List<DTOAuthor> SaveAuthors(List<DTOAuthor> auths)
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.SaveAuthors(auths.ToArray());
                    client.Close();
                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return authors;
            }

            public DTOPayroll GetPayRollByAuthorID(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dtopayroll = new DTOPayroll();
                try
                {
                    dtopayroll = client.GetPayRollByAuthorID(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return dtopayroll;
            }
            public void UpdatePayRollSalary(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
                try
                {
                    client.UpdatePayRollSalary(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOPayroll AddPayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOPayroll();
                try
                {
                    dto = client.AddPayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public void DeletePayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();

                try
                {
                    client.DeletePayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOArticle GetArticleTop1()
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();

                try
                {
                    dto = client.GetArticleTop1();
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public DTOArticle GetArticle(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();

                try
                {
                    dto = client.GetArticle(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public List<DTOArticle> GetArticles()
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtos = client.GetArticles();
                    client.Close();
                    articles.AddRange(dtos.Select(dto => new DTOArticle
                    {
                        ArticleID = dto.ArticleID,
                        AuthorID = dto.AuthorID,
                        Title = dto.Title,
                        Body = dto.Body
                    }));
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return articles;
            }

            public List<DTOArticle> SaveArticles(List<DTOArticle> artcs)
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtoarticles = client.SaveArticles(artcs.ToArray());
                    client.Close();

                    articles.AddRange(dtoarticles.Select(dtoarticle => new DTOArticle()
                    {
                        ArticleID = dtoarticle.ArticleID,
                        AuthorID = dtoarticle.AuthorID,
                        Title = dtoarticle.Title,
                        Body = dtoarticle.Body,
                        IsUpdate = dtoarticle.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

              return articles;
            }

            public void DeleteArticle(DTOArticle article)
            {
                var client = new WCFServiceReference.Service1Client();

                try
                {
                    client.DeleteArticle(article);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }
        }
    }


    Here is WPF using MVVM that is using the Service layer that is being past into the ViewModels.

    using System.Globalization;
    using System.Windows;
    using System.Windows.Markup;
    using System;
    using DemoWPFApp.ViewModel;
    using Services;

    namespace DemoWPFApp
    {
        public partial class App : Application
        {
            static App()
            {
                // This code is used to test the app when using other cultures.
                //
                //System.Threading.Thread.CurrentThread.CurrentCulture =
                //    System.Threading.Thread.CurrentThread.CurrentUICulture =
                //        new System.Globalization.CultureInfo("it-IT");

                // Ensure the current culture passed into bindings is the OS culture.
                // By default, WPF uses en-US as the culture, regardless of the system settings.
                //
                FrameworkElement.LanguageProperty.OverrideMetadata(
                  typeof(FrameworkElement),
                  new      FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
            }

            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);

                MainWindow window = new MainWindow();


                // Create the ViewModel to which
                // the main window binds.
                var viewModel = new MainWindowViewModel(TheService1.Instance);

                // When the ViewModel asks to be closed,
                // close the window.
                EventHandler handler = null;
                handler = delegate
                {
                    viewModel.RequestClose -= handler;
                    window.Close();
                };
                viewModel.RequestClose += handler;

                // Allow all controls in the window to
                // bind to the ViewModel by setting the
                // DataContext, which propagates down
                // the element tree.
                window.DataContext = viewModel;

                window.Show();
            }
        }
    }


                                  
    • Marked as answer by rushabh.shah Wednesday, September 9, 2015 6:02 PM
    Wednesday, September 2, 2015 3:35 AM

All replies

  • Maybe, you should be using a WebAPI service that is Json based. If you want to use WCF, then burry it on the backend behind the WebAPI.

    http://www.dotnetfunda.com/articles/show/2691/get-method-to-call-web-api-using-jquery-ajax

    https://msdn.microsoft.com/en-us/library/Hh833994%28v=VS.108%29.aspx?f=255&MSPPError=-2147217396

    <copy>

    ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

    <end>

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf

    http://forums.asp.net/1246.aspx/1?Web+API

    Tuesday, September 1, 2015 5:50 PM
  • Thanks for the response. I did go over the references you have suggested. But at this moment converting our current WCF will be a lot of work for us and still we are not sure whether it will increase the performance or not.

    Below is the AJAX call we are making to WCF service and WCF method.

    AJAX Call /*Execute following function when User Click on Log Out Button*/ function SignOut() { var username = document.getElementById("hid_username").value.toUpperCase().trim(); $.ajax({ type: "POST", url: app.config.hostUrl + "UserSignOut?" + Math.random(), dataType: "json", contentType: "application/json; charset=utf-8", data: '{"user":"' + username + '","uid":"' + device.uuid + '"}', success: function (result) { console.log(JSON.stringify(result));

    }, error: function (result) { console.log("INDEX VIEW" + result); } }); }

    WCF Method:

    [ServiceContract(Namespace = "")] [ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerCall)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 { #region User Sign OUT //Execute following method to delete user details like device UIDS from MobileDeviceUIDS [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public IEnumerable UserSignOut(string user, string uid) { DataObjectClass SqlNS = new DataObjectClass(); ArrayList paramvals = new ArrayList(); paramvals.Add(user); paramvals.Add(uid); return SqlNS.SqlExecScaler("dbo.CargoTrak_UserSignOut", "@Operator;;@UID", paramvals, true); } #endregion

    }


    Tuesday, September 1, 2015 8:40 PM
  • Hello Rushabh.shah,

    In general the client would need the same settings as in the binding section but not the service behavior section.

    As you have spotted there are many settings that influence the performance of a hosted service.  Unfortunately there is not a one size fits all approach so increasing the buffer size and receive size might help in some situations but not others. 

    My suggestion is to first identify where the bottleneck is happening.  

    • Do you have many clients connecting at the same time?
    • Are the clients sending/receiving large amounts of data in a single request?
    • Is a single client reusing its proxy or recreating it for each request?
    • Is the performance issue in your control (network latency vs. service request time)?
    • How is this hosted: IIS vs windows process?

    Most of the above can be determined by enabling WCF tracing on both the client and service.  In your situation I would look at enabling the performance counters. https://msdn.microsoft.com/en-us/library/ms735098(v=vs.110).aspx 

    You might find that the service request is taking the bulk of the time so you should concentrate on tuning your service implementation; or you might find that you have too many concurrent clients connecting at a time so you need to stand up an additional service in addition to increasing your serviceThrottling settings.


    Jeff

    Tuesday, September 1, 2015 8:51 PM
  • Hi rushabh.shah,

    According to this issue, as far as I know, when we want to  optimize WCF Service. We can

    use the follow  technologies include transactions ,session , reliable  transport messaging, as well as

    asynchronous operations. Sometimes we can use load balance to improve the WCF optimization.

    For more information, please refer the following articles:

    1.Transactions in WCF

    2.Sessions, Instancing and Concurrency in WCF Services

    3.Introduction to Reliable Messaging with the Windows Communication Foundation

    4.Synchronous and Asynchronous Operations

    5.Performance Tuning WCF Services, Part 1

    I hope that will be helpful to you.

    Best Regards,

    Grady


    Wednesday, September 2, 2015 2:31 AM
    Moderator
  • Thanks for the response. I did go over the references you have suggested. But at this moment converting our current WCF will be a lot of work for us and still we are not sure whether it will increase the performance or not.

    I didn't say anything about a conversion. What I said was bury the WCF service behind the WebAPI controllers. If you have a Service Layer classlib project that consumes the WCF service, then the WebApi controller is making calls to the ServiceLayer that in turn is making calls to the WCF service with the WCF service as/is, and the WebAPI can use Jason and Ajax with the client.

    The Service Layer below  I use where the BLL and DAL are setting behind the WCF Web service, which you don't have to do it that way. The key is what is happening with the Service Layer.

    Where did I get the Service Layer concept?

    http://polymorphicpodcast.com/shows/mv-patterns/

    Now,  you don't have to use the Service.Instance, because of IoC frameworks like Unity, Castel Windsor and other to create an instance of the Service object.

    using System.Collections.Generic;
    using BLL.DTO;

    namespace Services.IServices
    {
        public interface IService1
        {
            List<DTOAuthor> GetAuthors();
            List<DTOAuthor> GetAuthorsWhere();
            List<DTOAuthor> SaveAuthors(List<DTOAuthor> authors);
            DTOPayroll GetPayRollByAuthorID(int id);
            void UpdatePayRollSalary(DTOPayroll pr);
            DTOPayroll AddPayRoll(DTOPayroll pr);
            void DeletePayRoll(DTOPayroll pr);
            DTOArticle GetArticleTop1();
            DTOArticle GetArticle(int id);
            List<DTOArticle> GetArticles();
            List<DTOArticle> SaveArticles(List<DTOArticle> articles);
            void DeleteArticle(DTOArticle srticle);
        }

    The Service Layer itself that allows me to decouple the frontend of ASP.NET UI using MVP, ASP.NET MVC UI,  Windows form UI using MVP and WPF MVVM UI. Each one of the frontend UI(s) are doing the same functionality. The Service Layer and out don't care what the client UI is about.

    The Service Layer classlib project that consumes the WCF Web service.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using BLL.DTO;
    using Services.IServices;

    namespace Services
    {
        public class TheService1 : IService1
        {
            private static readonly TheService1 mInstance = null;


            public static TheService1 Instance
            {
                get { return mInstance; }
            }

            static TheService1()
            {
                mInstance = new TheService1();
            }

            public List<DTOAuthor> GetAuthors()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.GetAuthors();
                    client.Close();


                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor()
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return authors;
            }
            public List<DTOAuthor> GetAuthorsWhere()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.GetAuthorsWhere();
                    client.Close();
                   authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return authors;
            }

            public List<DTOAuthor> SaveAuthors(List<DTOAuthor> auths)
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();
                try
                {
                    var dtoauthors = client.SaveAuthors(auths.ToArray());
                    client.Close();
                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return authors;
            }

            public DTOPayroll GetPayRollByAuthorID(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dtopayroll = new DTOPayroll();
                try
                {
                    dtopayroll = client.GetPayRollByAuthorID(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
                return dtopayroll;
            }
            public void UpdatePayRollSalary(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
                try
                {
                    client.UpdatePayRollSalary(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOPayroll AddPayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOPayroll();
                try
                {
                    dto = client.AddPayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public void DeletePayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();

                try
                {
                    client.DeletePayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOArticle GetArticleTop1()
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();

                try
                {
                    dto = client.GetArticleTop1();
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public DTOArticle GetArticle(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();

                try
                {
                    dto = client.GetArticle(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public List<DTOArticle> GetArticles()
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtos = client.GetArticles();
                    client.Close();
                    articles.AddRange(dtos.Select(dto => new DTOArticle
                    {
                        ArticleID = dto.ArticleID,
                        AuthorID = dto.AuthorID,
                        Title = dto.Title,
                        Body = dto.Body
                    }));
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return articles;
            }

            public List<DTOArticle> SaveArticles(List<DTOArticle> artcs)
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtoarticles = client.SaveArticles(artcs.ToArray());
                    client.Close();

                    articles.AddRange(dtoarticles.Select(dtoarticle => new DTOArticle()
                    {
                        ArticleID = dtoarticle.ArticleID,
                        AuthorID = dtoarticle.AuthorID,
                        Title = dtoarticle.Title,
                        Body = dtoarticle.Body,
                        IsUpdate = dtoarticle.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

              return articles;
            }

            public void DeleteArticle(DTOArticle article)
            {
                var client = new WCFServiceReference.Service1Client();

                try
                {
                    client.DeleteArticle(article);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }
        }
    }


    Here is WPF using MVVM that is using the Service layer that is being past into the ViewModels.

    using System.Globalization;
    using System.Windows;
    using System.Windows.Markup;
    using System;
    using DemoWPFApp.ViewModel;
    using Services;

    namespace DemoWPFApp
    {
        public partial class App : Application
        {
            static App()
            {
                // This code is used to test the app when using other cultures.
                //
                //System.Threading.Thread.CurrentThread.CurrentCulture =
                //    System.Threading.Thread.CurrentThread.CurrentUICulture =
                //        new System.Globalization.CultureInfo("it-IT");

                // Ensure the current culture passed into bindings is the OS culture.
                // By default, WPF uses en-US as the culture, regardless of the system settings.
                //
                FrameworkElement.LanguageProperty.OverrideMetadata(
                  typeof(FrameworkElement),
                  new      FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
            }

            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);

                MainWindow window = new MainWindow();


                // Create the ViewModel to which
                // the main window binds.
                var viewModel = new MainWindowViewModel(TheService1.Instance);

                // When the ViewModel asks to be closed,
                // close the window.
                EventHandler handler = null;
                handler = delegate
                {
                    viewModel.RequestClose -= handler;
                    window.Close();
                };
                viewModel.RequestClose += handler;

                // Allow all controls in the window to
                // bind to the ViewModel by setting the
                // DataContext, which propagates down
                // the element tree.
                window.DataContext = viewModel;

                window.Show();
            }
        }
    }


                                  
    • Marked as answer by rushabh.shah Wednesday, September 9, 2015 6:02 PM
    Wednesday, September 2, 2015 3:35 AM