2

I was trying to generate proxy for a service using the code snippet mentioned here but I realized that the snippet is only for asmx services. Is there anyway to do the same for WCF services in c#?

Community
  • 1
  • 1
Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44
  • Your linked example should work for anything that exposes WSDL, have you tried it? – Preston Guillot Mar 02 '16 at 18:20
  • @PrestonGuillot, yes I tried that. It actually generates the output same as what we get when asmx service is consumed. For instance, the interface defined as ServiceContract in WCF service was generated as partial class with name WsHttpBinding_InterfaceName in the output. – Pratik Gaikwad Mar 02 '16 at 18:22
  • Maybe this is what you're looking for: https://benmccallum.wordpress.com/2011/08/27/wcf-web-service-wrapper-closing-disposing-and-aborting-best-practices/ – lintmouse Mar 02 '16 at 18:46
  • @dustmouse, the code, in the article, is just refactored to create and dispose channel dynamically for every proxy object. In the end Template(T) is still interface or SericeContract from WCF service. – Pratik Gaikwad Mar 02 '16 at 18:51

1 Answers1

0

Okay. After much searching found two classes which can do this for us along with help from others.

  1. codecompiler
  2. WSDLimporter

These two provide a way to download wsdl at runtime, extract contract and endpoint info and create code in C# or VB which can be compiled to create assembly on which reflection can be used to invoke WCF Service.

Hope this helps somebody someday!

Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44