I was setting up a Man in the Middle webservice to intercept a message coming in so that I could do some processing of it on the side. Don't worry, it was our webservice. My process is fairly simple:
- accept the submitted object
- forward the object to the old web service
- do what I wanted with the info
Step #2 appears fairly straightforward, and for the most part it is.
- Create a (new) Web Service.
- Expose the same public WebMethods.
- Add a 'Web Reference' to the (old) Web Service
- Create a new Web Service object of the old Web Service
- Pass the received object onward
The problem that occurs is that because the (new) Web Service has to be all-inclusive it creates its own object type. While this is acceptable in .Net (since it goes by .net classnames) this gets all out of whack in the XML. This is because the XML uses a different namespace process - and since the (new) Web Service uses the same object as the (old) Web Service, albeit with a different .net namespace one of the things that it includes as an Attribute is the XML namespace. So
- The two classes have different .net namespaces
- The two classes have the exact same XML namespace
The compiler does not catch this because it is only looking at the .net namespace. So it will give you all sorts of helpful suggestions.
However....
There is a simpler way to do it. Basically, since you KNOW that the incoming and outgoing objects are the same, you are simply going to override the class that the Web Reference uses to tell it to use the original class.
If you initially open up the Web Reference to your (old) Web Service you are not going to see the file you need. You need to go up to the File Menu and select Project, Show All Files.

Now you will see the file that you want over in the Solution Exploerer -> Reference.cs.

Open that puppy up and make the necessary changes, just remember to wipe out the (new) objects that will be in there. All you want to leave are the methods, and those should now be passing the classes from the (old) Web Service.
Happy coding!