WPF DataGrid Designer Config with WCF Service Data Source

Mar 9, 2009 at 10:37 PM
Edited Mar 9, 2009 at 10:47 PM
I am accessing a WCF service through my WPF DataGrid which works fine at run time. But I am trying to get the right XAML setup so I can customize the DataGrid object in the designer.

I keep getting a "endpoint error" in the designer at Design time when I setup my ObjectDataProvider as a Windows resource so I can bind the DataGrid in XAML using the ItemsSource keyword.

Error Message: 
"Could not find default endpoint element that references contract 'RoomReservationService.IRoomService' 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."
  

<Window.Resources>
<!-- create an instance of our DataProvider class -->
<ObjectDataProvider ObjectType="src:GetListData" MethodName="DefineListData" x:Key="RoomDataProvider"/> 
 
</Window.Resources>
...


<mydgtkt:DataGrid Name="dgrdMyDataGrid"
ItemsSource="{Binding Source={StaticResource RoomDataProvider}}" Margin="46,115,70,24">
</mydgtkt:DataGrid>

 

 

app.Config

<client>
<
endpoint address="http://localhost:8731/Design_Time_Addresses/RoomReservationService/RoomReservationService/"
                  
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRoomService2"
                  
contract="RoomReservationService.IRoomService" name="WSHttpBinding_IRoomService2">
                 <
identity>
                             <
dns value="localhost" />
                </
identity>
</
endpoint>
</client

 

 

 

 

 

 

 

May 10, 2009 at 7:37 AM

I had the same problem. It has something to do with the designer trying to init the WCF client and failing, or trying to execute your ObjectDataProvider method. In my case I put both of these sections in the code into try-catch blocks and that solved it.

 

 

 

 

 

 

 

<font size="2">

 

</font>

 

 

public WCFDataProvider()
(
   try
  
{
     
this.wcfClient = new WCFClient();
   }
  
catch(Exception){}
)

public
TaskObjects GetTasks()
{
TaskObjects tasks = new TaskObjects();
try
{
  
Task[] dbTasks = this.wcfClient.GetTasks();
  
foreach(Task dbTask in dbTasks)
   {
      tasks.Add(dbTask);
   }
}
catch(Exception){}
return tasks;
}

The other thing that can cause the designer to fail to enumerate the ObjectDataProvider is if your GetWhateverDataFromWCF() method returns null on exception/failure. As you can see in my method I return an empty collection. Once I did that the designer suddenly started working.