Two web services + same objects = It's time to discošŗ [How to create a proxy class between wsdls]
csharp english exe wsdl
TLDR;
Create discomap files with the following command:
disco.exe "file:///[Local path to file]\file.wsdl"
Use the wsdl.exe to create proxy classes with the following command:
wsdl.exe /shareTypes [path to discomap file for ws 1] [path to discomap file for ws 2]... /o: [path to proxy class] /n: [namespace of proxy class]
āāā
THE JOURNEY TO OBTAIN THE KNOWLEDGE TO CREATE THE TLDR;
Letās say that you have two or more web services that you need to use in your app. You download them into your project, implement the first one and when youāre going to implement the second one, you realize that it has the same objects as the first, and that they need to be filled up exactly the same way but, because theyāre inside their own wsdl, you would need to do it separately. Effectively making your code *wet*.
As you can imagine, I was not having any of this when I found myself facing this exact problem. So I headed into googlelandia and set up a trip to find a solution for this. Ah yes the first thing youāll read is to use the wsdl.exe command ā/sharedtypeā. Thatās it. Thatās the solution, so why did it take me a day to make it work?
Because Iām my teamās Jon Snow thatās why. So, I decided to create this guide for all of the programming Jon Snows out there. No need to thank me.
Yet.
we donāt pet doggies here
First things first. You need to know what a discomap is. Itās an extension, an xml file that allows your web service to be discoverable and eeehā¦ Iām going to honest, I didnāt and donāt care much about what its true life purpose is but, because Iām dumb and didnāt know the file:/// extension to create local URI paths, I learned how to create them since I only had the WSDL file.
So, boot up you visual studioās command prompt and paste whatever code you think youāll need based on that one lonely SO answer:
wsdl.exe /sharedtypes <path to first webservice wsdl file> <path to second webservice wsdl file>
Oh yeah, since Iām, like, ME. I headed to the Package Manager Console first š
Tip #1: THE FOLLOWING IS NOT A COMMAND PROMPT:
You can find the actual command prompt here:
And it should look like this:
Now CD that into your web service folder, maybe itās called āWeb Referencesā. Right outside there. Nothing badās going to happen I SWEAR.
So run that code.
Bam bam bam, it throws a million errors at ācha. Because you CDād wrong.
Prompt: "What do you mean WEB(SPACE)REFERENCE?"
Since youāre stressed out, know nothing about CMD except for the command āipconfigā and āpingā and, need to finish like pront-o, I suggest you CD by folder like this:
cd /Folder1
cd /Folder2
...
It works. Long live practicality.
Now run your code!!
.
.
.
IT. DOESNT. WORK. AGH. š”
Since you donāt know about the file:/// to create a URI for a local file, itāll tell you that it needs a disco. FORREAL. Itās telling you that it needs a discomap file, but you only have your WSDL file. What to do? you use the Web Services Discovery Tool (Disco.exe), thatās what.
In the same command prompt, run this code:
disco.exe "[Local path to file]\file.wsdl"
Ah! an error message. Remember that Iāve been saying that I didnāt know how to make local paths into URIs? At this point I had to finally learn that ā file:///ā exists. Once I did learn it though, I had to think long and hard if I should try using it for the wsdl.exe with it but, I decided to learn how to create discomap files for wsdls. Valuable.
The new code will be like this:
disco.exe "file:///[Local path to file]\file.wsdl"
Cool, the discomap files should create itself in the same folder as the WSDL. Now we can use the to create our proxy class in the wsdl.exe tool.
But before creating it, Iām going to give you two more tips.
Tip #2: The /o: command letās you set a filename or a directory name. I for one, had my own proxy class already created so I set the path to it. If you donāt set it, itāll create a proxy class probably named āresults.csā in the folder you CDād in.
Tip #3: The /n: command lets you specify the proxy classās namespace. Unless you want it set as global (note: this can cause issues with other web services not part of the proxy) use this.
The code now looks like this:
wsdl.exe /shareTypes [path to discomap file for ws 1] [path to discomap file for ws 2]... /o: [path to proxy class] /n: [namespace of proxy class]
If you get any schema issues ignore them. I promise you the proxy will work. I wasted like an hour in trying to fix it and itās simply not worth it, especially if itās not your own wsdl. A small note, sometimes itāll create the same object but with sequential numbers like 1, 2, 3ā¦ I got this because I went crazy and created a proxy for more than 4 web services. I donāt really know how to fix it but just a small warning.
Anyway, hopefully after going through this small journey with me youāll understand how I was able to create the proxy. It took me a day because thereās not a lot of decent explanations on the subject/problem so what Iām explaining here is a summary of everything I went through to get it to work.
Now go on and enjoy the proxy class š
We have now acquired the ability to pet doggies