1

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?

Ingó Vals
  • 4,788
  • 14
  • 65
  • 113

2 Answers2

3

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.

Bahri Gungor
  • 2,289
  • 15
  • 16
  • The web service is currently being used in another project succesfully so I'm pretty sure it works. Also it worked fine in the console application I messed around with. I guess it's a problem with the generation. I've tried to redo it but that doesn't help so I guess I'll have to look into svcutil.exe – Ingó Vals Jul 27 '11 at 15:13
  • Since you know the server service works, I must assume it is a client proxy or client configuration issue. Using the WCF Test client is helpful if the web method you are calling does not have complex structures. If it does, then you will need to trial and error. Be sure to use the WCF Service Configuration utility to avoid making mistakes in your app.config file (at least until you have high confidence that you are setting the right values). Provide more information if you continue to have trouble. – Bahri Gungor Aug 08 '11 at 20:58
  • I generated it using the svcutil.exe and it at least comes out normally. Just need to test it. – Ingó Vals Aug 09 '11 at 13:33
-1

now that you have generated the API, its time to start adding class instances and calling methods. really, that is all there is too it.

Check out this codeproject article for more detailed help.

BTW, a simple google for "using web services in wpf" revealed a metric-but-ton of results.

Muad'Dib
  • 28,542
  • 5
  • 55
  • 68
  • Well I guess you didn't read my post. To use a method I have to create a ServiceClient, correct? Well the serviceClient doesn't appear in the list of objects. If I do the exact same thing in a console app the client appears and I can construct it. How come? – Ingó Vals Jul 27 '11 at 14:52