Search code examples
wpfweb-serviceswebservice-clientservice-referenceconsuming

Consuming a web service in a WPF app


I wan't to consume a web service inside a WPF app.

I can add the Service Reference and all the objects show up in the object browser except for the ServiceClient itself.

I tried adding the service to a console application and it all worked out there.

Is there some limit on WPF apps using web services.

I noticed that in the console app he added a ServiceModel node into the app.config file but not in the WPF app.config file.

Is there anything I can do to make it work?


Solution

  • To answer your question specifically, no, there is nothing in WPF that would prevent you from using WCF to create a web service reference.

    I have, however, run into issues (in general) with using the "Add Service Reference" for generating the proxy and service class.

    I would start by using the WCF Test Client to test that your web service operates correctly and a generic proxy can be generated.

    Once the WCF Test Client works, I would clean out the existing service reference. Make sure everything is deleted. Then add the service reference again.

    If you have a complex web service, or the interface contains complex structures, you may want to look into using svcutil.exe to generate your proxy.

    This is the best answer I can give with the information you've provided. I believe your issue is with the WCF proxy generation, however, not WPF. When learning about WPF, it is best to keep your service as simple as possible and verify that the communication works before adding anything that could break WPF (like passing a dataset or class structure).

    P.S. Your executable app.config MUST have a system.serviceModel section to communicate, but its absence will not affect the reference and proxy generation.