views:

175

answers:

1

Hi, 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 'MainWindow' 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?

A: 

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.

Mart
Yes, I got it too now but then I've got empty response from service. I was created global app.config file for both projects and it works.
Kamilos
What do you mean by "empty response"? If you get a response then your service is working. The error is somewhere else, in your service itself of you have multiple service instances and calling the wrong one, etc.
Mart
response.Succeed was true but all data was null, can't add new service reference to one of projects, but it's other problem (VS bug?) - when I copy it from other project and change manually in csproj and Reference.cs it works... strange. Just while adding new service reference it seems to be added (no error) but it doesn't.
Kamilos
Then verify that the way you reference the service (including the "Advanced" screen) is the same as in the working project, and that in both cases you're really referencing the same service assembly.
Mart