WCF hosted in WPF and how can i change control in MainWindow UI from wcf?

Faraz

I write WCF code and hosted in my WPF app. I write class to switch my MainWindow to show other page in my project

public static class Switcher
    {
        public static MainWindow pageSwitcher;

        public static void Switch(Page newPage)
        {
            pageSwitcher.Navigate(newPage);
        }       
    }

and I write my wcf service like this:

[ServiceContract]
    public interface IAppManager
    {
        [OperationContract]
        void DoWork();
        [OperationContract]
        void Page1();
        [OperationContract]
        void Page2();
    }
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class AppManager : IAppManager
    {

        public void DoWork()
        {
        }
        public void Page1()
        {
            MainWindow.pageSwitcher = new MainWindow();
            MainWindow.Switch(new Page1());
        }
        public void Page2()
        {
            MainWindow.pageSwitcher = new MainWindow();
            MainWindow.Switch(new Page2());
        }
    }

I want change page remotely from another computer with WCF but it not work and I trace code the wcf is run and response but do not do anything how can access to main thread to change ui page or other element?

slugster

Your current solution is unusual, but WCF can be hosted in a WPF application. However you should never try to directly manipulate the UI from the WCF service - you'll have cross thread issues to begin with.

What you should consider doing is using messaging via a pub-sub broker (image linked from MSDN):

enter image description here

Something that fits this bill nicely is Prism's EventAggregator. A couple of samples I cherry picked are Simplifying PRISM’s EventAggregator and Prism EventAggregator Sample.

The way you use this is the service registers events and then raises them, the WPF subscribes to those events and processes them. With this you can also specify whether to receive the events on the UI thread or a background thread.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

WCF service - which parts can be excluded from source control?

分類Dev

WCF hosted with IIS performance Tuning

分類Dev

How to access ChildWindow TextBox from MainWindow in WPF

分類Dev

Unable to consume WCF service (hosted in IIS )

分類Dev

Self-Hosted WCF - Namespace Reservation required?

分類Dev

WCF Service 413 no matter which config item I change

分類Dev

WPFでホストされているWCFと、MainWindow UIのコントロールをwcfから変更するにはどうすればよいですか?

分類Dev

How do I suppress the method name from my xml in a WCF Web Service?

分類Dev

How to consume WCF Data Service from Controller (MVC5, EF6, WCF 5.6)

分類Dev

WPF Change View from a User Control MVVM

分類Dev

how to run SVCUtil of WCF

分類Dev

How can I change Image in Listview during runtime in WPF?

分類Dev

Can I change Min SDK version for a hosted app?

分類Dev

Self-hosted WCF service works with HTTP not with HTTPS

分類Dev

WCF "Basic" transport security issue when hosted in IIS

分類Dev

How to throw an exception from callback in WCF Async using IAsyncResult

分類Dev

How to access a WCF service from F# in .NET Core 3.1?

分類Dev

how to Deserialize Json response from WCF Restful Service?

分類Dev

How can i change the hover style of a PrimaryButton in Fluent UI?

分類Dev

How can I pip install pyx package from externally hosted source?

分類Dev

Embedded image resource in hosted WPF control

分類Dev

How can I access a string from another class in WPF

分類Dev

How to return message in the WCF endpoint?

分類Dev

WPF: How can I use multiple list views in a control size correctly?

分類Dev

After migrating to Azure, how can I query my organization Active Directory from within the application now hosted in Azure?

分類Dev

Why can't service host from Unity.Wcf resolve service's instance correctly?

分類Dev

WPF UI Control Background changing

分類Dev

How can i change screen resolution on mac remote control for a windows 2008 Server?

分類Dev

How can I calculate cumulative percentage change from beginning period

Related 関連記事

  1. 1

    WCF service - which parts can be excluded from source control?

  2. 2

    WCF hosted with IIS performance Tuning

  3. 3

    How to access ChildWindow TextBox from MainWindow in WPF

  4. 4

    Unable to consume WCF service (hosted in IIS )

  5. 5

    Self-Hosted WCF - Namespace Reservation required?

  6. 6

    WCF Service 413 no matter which config item I change

  7. 7

    WPFでホストされているWCFと、MainWindow UIのコントロールをwcfから変更するにはどうすればよいですか?

  8. 8

    How do I suppress the method name from my xml in a WCF Web Service?

  9. 9

    How to consume WCF Data Service from Controller (MVC5, EF6, WCF 5.6)

  10. 10

    WPF Change View from a User Control MVVM

  11. 11

    how to run SVCUtil of WCF

  12. 12

    How can I change Image in Listview during runtime in WPF?

  13. 13

    Can I change Min SDK version for a hosted app?

  14. 14

    Self-hosted WCF service works with HTTP not with HTTPS

  15. 15

    WCF "Basic" transport security issue when hosted in IIS

  16. 16

    How to throw an exception from callback in WCF Async using IAsyncResult

  17. 17

    How to access a WCF service from F# in .NET Core 3.1?

  18. 18

    how to Deserialize Json response from WCF Restful Service?

  19. 19

    How can i change the hover style of a PrimaryButton in Fluent UI?

  20. 20

    How can I pip install pyx package from externally hosted source?

  21. 21

    Embedded image resource in hosted WPF control

  22. 22

    How can I access a string from another class in WPF

  23. 23

    How to return message in the WCF endpoint?

  24. 24

    WPF: How can I use multiple list views in a control size correctly?

  25. 25

    After migrating to Azure, how can I query my organization Active Directory from within the application now hosted in Azure?

  26. 26

    Why can't service host from Unity.Wcf resolve service's instance correctly?

  27. 27

    WPF UI Control Background changing

  28. 28

    How can i change screen resolution on mac remote control for a windows 2008 Server?

  29. 29

    How can I calculate cumulative percentage change from beginning period

ホットタグ

アーカイブ