How to Bind a WPF control to a WCF method using an ObjectDataProvider -


I am testing WPF for the first time and I am trying to call the WCF service with an ObjectDataProvider.

The WCF service is named WCfService1 with one method:

  Namespace WCFService1 {Public class Service1: IService1 {public string hello () {return "Hello World!"; I've added a service reference for my WPF project and designated it as TestService  

In my main window, I can call without calls without code, it seems simple; Like a web service call:

TestService.Service1Client Service = New TestService.Service1Client (); MessageBox.Show (service.HelloWorld ());

I am trying to create an ObjectDataProvider which indicates this service. I think what should I be doing as an object type? I have tried local, service namespace, src; I'm lost:

  & lt; window. Resources & gt; & Lt; ObjectDataProvider x: key = "odpTestService" object type = "{x: type ** test service service: service 1 client}" methodname = "helloard" /> & Lt; /Window.Resources>  

Eventually it will be linked to a text block:

  & lt; TextBlock Grid.Column = "0" grid. Line = "0" grid Column aspen = "2" background = "Alice-Blue" text = "{binding source = {static RSSS ODPTSS service}}" />  

I was trying to work with the Flickr example posted here:

Update: Reply from Dennis Solved . Now, I'm getting an error on the compilation: System.Windows.Data Error: 34: ObjectDateProvider: Failure to try to apply the method to type;

ObjectDataProvider HelloWorld Method Type IService1 Using the method and type from my example) Any ideas why?

You must import the namespace of service through an xmlns directive at the top of the file:

Assuming that the context has been directly added to your application, and that the root namespace of your application is "MyApplication":

  & lt; Window x: class = "MyApplication .myWindow" xmlns: srv = "MyApplication.TestService" & gt; & Lt; Window.Resource & gt; & Lt; ObjectDataProvider x: key = "odpTestService" object type = "{x: type srv: Service1Client}" methodname = "helloard" /> & Lt; /Window.Resources> & Lt; TextBlock Grid.Column = "0" grid. Row = "0" grid. Colspan = "2" background = "aliceblue" text = "{binding source = {static resource odptext service}}" /> & Lt; / Window & gt;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -