Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent generation of proxy classes in Reference.cs when adding/updating a web reference

I have a web service and a client. The classes used in parameters and return types are in a common DLL shared by both. However, whenever I update the web reference, visual studio generates copies of the classes with the same names and public properties and methods. Then the solution won't compile because the client code tries to use the versions in the common DLL. I can solve the problem by deleting the "duplicate" classes every time I update the web reference, and adding a using statement to point at the common dll's namespace. Is there a way to fix this permanently?

UPDATE: See my comments below. This is a "feature" of asmx web services. There is no way around it other than one of the following: 1) Use a more modern type of web service. 2) Don't use a common DLL 3) Manually fix every time you update the web reference, as in the original question above.

like image 674
stannius Avatar asked Aug 14 '12 17:08

stannius


People also ask

How a proxy is generated and used for a web service?

A proxy class maps parameters to XML elements and then sends the SOAP messages over a network. In this way, the proxy class frees you from having to communicate with the Web service at the SOAP level and allows you to invoke Web service methods in any development environment that supports SOAP and Web service proxies.

What is the command line utility used to create a proxy class for a web service?

After creating the directory we will write a Proxy class by “wsdl” command on a specified location. Just write wsdl and paste your URL that was copied from the web browser of the web service file . asmx and press Enter to create it. It will create a Proxy class on the selected location.

What is proxy class in webservice C#?

The proxy class handles the work of mapping parameters to XML elements and then sending the SOAP message over the network. Wsdl.exe is a Microsoft . NET tool which is used to create proxies for C#, Visual Basic .

What is a web service proxy?

A web service proxy is a gatekeeper between a calling application and target web service. The proxy has the ability to introduce new behaviors within the request sequence. A Web Service proxy can then: • Add or remove HTTP headers.


2 Answers

This is a "feature" of asmx web services. There is no way around it other than one of the following:

  • Use a more modern type of web service.
  • Don't use a common DLL
  • Manually fix every time you update the web reference, as in the original question above.

Sources: Other stackoverflow questions:

  • "Reuse existing types" is ignored when adding a service reference
  • How does Visual Studio 2008 and svcutil decide which types to re-use from referenced assemblies when generating a web service proxy class?
like image 85
stannius Avatar answered Sep 29 '22 02:09

stannius


I had the same problem, but I had neglected to add the reference the correct assembly with the request/response types in my client. Once I added that reference, and ensured that the "Reuse types" checkbox was on in the Add Service Reference dialog, it worked properly.

like image 42
Ben Whitney Avatar answered Sep 29 '22 02:09

Ben Whitney