I have a simple WCF web service that works great if I create a new simple C# WPF application, adding the WCF Service Reference. Then I can access the methods/operationscontracts from the WCF service.
Eg:
Service1Client svc = new Service1Client();
svc.GetData()
If I create a WPF UserControl where I add the WCF service reference and instanciate with: Service1Client svc = new Service1Client(); - everything compiles fine Again (can't debug since it's just a UserControl).
But if I then import the .dll from the UserControl to a new C# WPF application and use the UserControl in the MainWindow.xaml it fails:
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code Additional information: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
How is that? Why can't I use the WCF Service Reference in a WPF UserControl that gets used in another WPF Mainapplication?
I have searched and searched for this but nothing helpful found.
Best regards
EDIT #1
I added the System.ServiceModel to my MainApplication (Thank you for pointing that out) I get the same error
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code Additional information: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I guess the problem is that the MainApplication don't know the endpoint, from the app.config from the UserControl Library.
I have to copy this part from the app.config (UserControl Library) to the MainApplication App.config The it will compile and start up and it works.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="DELETED" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
But I still get Error in Visual Studio i live design view in MainWindow.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfControlLibrary1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1" x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WpfControlLibrary1:UserControl1/>
</Grid>
I get Error on the and can't see the UserControl in Live view (Cannot create an instance of "UserControl1")
And from the Error list:
Error 1 Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. DELETED\WpfApplication1\WpfApplication1\MainWindow.xaml 7 9 WpfApplication1