I’m consuming a webservice from another company, they have multiple versions running, each newer version has only added new fields/objects, BUT changes some of the element names.
I would like the ability to consume any of the versions with the same code.
Specifically In one version a search method returns:
<searchReturn><SummaryData_Version1Impl /><SummaryData_Version1Impl /></searchReturn>
and in a different version: <searchReturn><SummaryData_Version2Impl /><SummaryData_Version2Impl /></searchReturn>
So right now the proxy generated by wsdl.exe cannot work with both because of that element change.
- The best solution would be to make the other company fix their service to not change the element names, but that is fairly unlikely in this situation
- I’m thinking my best bet for a working solution is to send and get the SOAP request manually, and modify the element names then deserialize manually which so far has seemed like it would work. — But would require quite a bit of work
- I just confirmed that manually loading the xml (after changing the element name with string.Replace) will deserialize any version of the service into the needed objects
- Alternatively do a similar thing by modifying the generated proxy:
- If i could intercept and modify the soap response before the generated proxy tries to deserialize it
- If I could modify the XmlTypeAttribute of the service at runtime
- I’ve also thought of having a series of interfaces, so each class would have the interfaces of the older
class Data3 : IData3, IData2, IData1Which I’m thinking would allow me to at least cast downward. And put each version into a different namespace. - There is a couple duck typing techniques I have just looked into slightly which might be able to work, but seems less reliable.
- Is there any other way to deserialize from multiple element names?
I now think the best option is to use a SoapExtension and set a SoapExtensionAttribute to trigger using that on any methods you need to modify the response for.
[ModifyResponseExtensionAttribute]to any methods that require the modifications, in your case you might need multiple SoapExtension classesAdd the following classes to your project:
So it is very possible to manually modify the request/responses of the wsdl.exe generated class when needed.