How to customize the Web Service proxy generated by wsdl.exe (or add web references)


The goal of this article is to explain how we can share and use messages definitions in Web Services architecture.

When you design your application, you need to specify messages to allow communication between layers. Messages definitions will be shared and distributed in a separate assembly. But, when you generate your proxy with wsdl.exe (or add web reference), the definition of your messages is the same but with a different namespace defined in you shared assembly.

With the framework 2.0, there are two possibilities to resolve this problem:

I : Expand the Generated Code

The goal is to use the partial class notion. Here, you don’t modify but you expand the generated code with partial class.

On the shared assembly (messages definitions):

1. Messages objects in your shared assembly should implement interface


On the server side:

1. Create a Web Method which returns an object defined in your shared assembly


On the client side:

1. Create a partial class with the same name that Messages define in the generated proxy

2. Call the Web Service and get the result 🙂


II: Modify the generated code

The second solution is to use the Schema importer service which allows you to customize the code generated by wsdl.exe. The following article explain what is Schema importer service and how to use it:

http://www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx


Comments (2)
  1. Sometimes we may need to customize the auto-generated webservice proxy(such as change some type definition

Comments are closed.

Skip to main content