Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4110316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:55:06+00:00 2026-05-20T21:55:06+00:00

I’m consuming a webservice from another company, they have multiple versions running, each newer

  • 0

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.

  1. 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
  2. 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
  3. 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
  4. I’ve also thought of having a series of interfaces, so each class would have the interfaces of the older class Data3 : IData3, IData2, IData1 Which I’m thinking would allow me to at least cast downward. And put each version into a different namespace.
  5. There is a couple duck typing techniques I have just looked into slightly which might be able to work, but seems less reliable.
  6. Is there any other way to deserialize from multiple element names?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:55:06+00:00Added an answer on May 20, 2026 at 9:55 pm

    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.

    1. Modify the generated code and add the attribute [ModifyResponseExtensionAttribute] to any methods that require the modifications, in your case you might need multiple SoapExtension classes
    2. Add the following classes to your project:

      public class ModifyResponseExtension : SoapExtension
      {
          Stream inStream;
          Stream outStream;
      
          // Save the Stream representing the SOAP request or SOAP response into
          // a local memory buffer.
          public override Stream ChainStream(Stream stream)
          {
              inStream = stream;
              outStream = new MemoryStream();
              return outStream;
          }
      
          //This can get properties out of the Attribute used to enable this
          public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
          {
              return null;
          }
      
          //This would have default settings when enabled by config file
          public override object GetInitializer(Type WebServiceType)
          {
              return null;
          }
      
          // Receive the object returned by GetInitializer-- set any options here
          public override void Initialize(object initializer)
          {
          }
      
          //  If the SoapMessageStage is such that the SoapRequest or
          //  SoapResponse is still in the SOAP format to be sent or received,
          //  save it out to a file.
          public override void ProcessMessage(SoapMessage message)
          {
              switch (message.Stage)
              {
                  case SoapMessageStage.BeforeSerialize:
                      break;
                  case SoapMessageStage.AfterSerialize:
                      //This is after the Request has been serialized, I don't need to modify this so just copy the stream as-is
                      outStream.Position = 0;
                      Copy(outStream, inStream);
                      //Not sure if this is needed (MSDN does not have it) but I like closing things
                      outStream.Close();
                      inStream.Close();
                      break;
                  case SoapMessageStage.BeforeDeserialize:
                      //This is before the Response has been deserialized, modify here
                      //Could also modify based on something in the SoapMessage object if needed
                      ModifyResponseMessage();
                      break;
                  case SoapMessageStage.AfterDeserialize:
                      break;
              }
          }
      
          private void ModifyResponseMessage()
          {
              TextReader reader = new StreamReader(inStream);
              TextWriter writer = new StreamWriter(outStream);
      
              //Using a StringBuilder for the replacements here
              StringBuilder sb = new StringBuilder(reader.ReadToEnd());
      
              //Modify the stream so it will deserialize with the current version (downgrading to Version1_1 here)
              sb.Replace("SummaryData_Version2_2Impl", "SummaryData_Version1_1Impl")
                  .Replace("SummaryData_Version3_3Impl", "SummaryData_Version1_1Impl")
                  .Replace("SummaryData_Version4_4Impl", "SummaryData_Version1_1Impl");
              //Replace the namespace
              sb.Replace("http://version2_2", "http://version1_1")
                  .Replace("http://version3_3", "http://version1_1")
                  .Replace("http://version4_4", "http://version1_1");
      
              //Note: Can output to a log message here if needed, with sb.ToString() to check what is different between the version responses
      
              writer.WriteLine(sb.ToString());
              writer.Flush();
      
              //Not sure if this is needed (MSDN does not have it) but I like closing things
              inStream.Close();
      
              outStream.Position = 0;
          }
      
          void Copy(Stream from, Stream to)
          {
              TextReader reader = new StreamReader(from);
              TextWriter writer = new StreamWriter(to);
              writer.WriteLine(reader.ReadToEnd());
              writer.Flush();
          }
      }
      
      // Create a SoapExtensionAttribute for the SOAP Extension that can be
      // applied to an XML Web service method.
      [AttributeUsage(AttributeTargets.Method)]
      public class ModifyResponseExtensionAttribute : SoapExtensionAttribute
      {
          private int priority;
      
          public override Type ExtensionType
          {
              get { return typeof(ModifyResponseExtension); }
          }
      
          public override int Priority
          {
              get { return priority; }
              set { priority = value; }
          }
      }
      

    So it is very possible to manually modify the request/responses of the wsdl.exe generated class when needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.