开发者

WPF - how to call another WPF with own service refences?

开发者 https://www.devze.com 2022-12-21 01:38 出处:网络
I have 2 WPF projects in 1 solution. Every of those projects have different service references. First project it\'s a window to login, second is a main window with app. It must be in separated project

I have 2 WPF projects in 1 solution. Every of those projects have different service references. First project it's a window to login, second is a main window with app. It must be in separated projects, don't ask why.

So, I do main window reference in login project and create main window object when login data is corect. Here sample of code:

try
{
    if (Service1.Login(login, pass))
    {
        MainWindow w2 = new MainWindow();
        w2.Show();
        this.Close();
    }
}
catch (Exception ex)
{
//...
}

My problem is error occured when main window is called. Main exception is like this:

"Cannot create instance of 'MainWin开发者_开发百科dow' defined in assembly 'TestApp, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an 
invocation.  Error in markup file 'MainWindow.xaml' Line 1 Position 9." 

Inner exception told me something like:

"Cannot found endpoint of service..."

But when I run just main window project as startup it works good. Is there any "proper" method to call other WPFs whit service references? Or I must to do something with references?


There is nothing wrong in your architecture (even if we can discuss about it), this is more a WCF question. Your problem comes from the fact that your Login app config file hos no endpoint defined for the MainWindow's service.

The Login app.config should contain two <endpoint .../> tags in the <configuration><system.serviceModel><client> section.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号