Question How to get nested complexType parameters for an operation from a SOAP wsdl?

whiteadi

Member
Joined
Nov 19, 2020
Messages
9
Programming Experience
10+
Having an WSDL and given one operation offered by it I want to parse it and fetch the input parameters for that operation, this example works for me only when there are no nested complex types:

How to parse an xsd file which has nested elements(complexType and simpleType elements and attributes)?

For this it works:

http://www.dneonline.com/calculator.asmx?wsdl

And that means it returns for all 4 operations the correct parameters (Add has AddSoapIn with intA and intB...)

but for this doesn't:

http://www.learnwebservices.com/services/hello?WSDL

It gets only to the HelloRequest for SayHello and does not fetch the element Name from HelloRequest.

This should work for any and not specific SOAP WSDLs, what I mean is a generic parsing.
 
As I said in post #4: step through the code with the debugger. Don't just run it. I think that you'll find that when you call OutputElements() on line 71 (which produced the output from line 138), that the rest of the foreach loop for in getParams() has not yet seen the succeeding elements.
I will check indeed monday, have anice week end!
 
Hi, I have added a few lines to OutputElements, see highligted ones (21-26):

C#:
private static List<Tuple<string, string, string>> OutputElements(XmlSchemaParticle particle, string parentName)
    {
        List<Tuple<string, string, string>> parameters = new List<Tuple<string, string, string>>();

        XmlSchemaSequence sequence = particle as XmlSchemaSequence;
        XmlSchemaChoice choice = particle as XmlSchemaChoice;
        XmlSchemaAll all = particle as XmlSchemaAll;

        if (sequence != null)
        {
            for (int i = 0; i < sequence.Items.Count; i++)
            {
                XmlSchemaElement childElement = sequence.Items[i] as XmlSchemaElement;
                XmlSchemaSequence innerSequence = sequence.Items[i] as XmlSchemaSequence;
                XmlSchemaChoice innerChoice = sequence.Items[i] as XmlSchemaChoice;
                XmlSchemaAll innerAll = sequence.Items[i] as XmlSchemaAll;
                
                if (childElement != null)
                {
                    parameters.Add(new Tuple<string, string, string>(childElement.Name, childElement.SchemaTypeName.Name, parentName));
                    // if it has children
                    List<Tuple<string, string, string>> moreparams = getParams(childElement.SchemaTypeName.Name, null);
                    if (moreparams != null && moreparams.Count != 0)
                    {
                        parameters.AddRange(moreparams);
                    }
                }
                else {
                    List<Tuple<string, string, string>> moreparams = OutputElements(sequence.Items[i] as XmlSchemaParticle, parentName);
                    if (moreparams != null && moreparams.Count != 0)
                    {
                        parameters.AddRange(moreparams);
                    }
                }
            }

            return parameters;
        }
        else if (choice != null)
        {
            Console.Out.WriteLine("  Choice");
            for (int i = 0; i < choice.Items.Count; i++)
            {
                XmlSchemaElement childElement = choice.Items[i] as XmlSchemaElement;
                XmlSchemaSequence innerSequence = choice.Items[i] as XmlSchemaSequence;
                XmlSchemaChoice innerChoice = choice.Items[i] as XmlSchemaChoice;
                XmlSchemaAll innerAll = choice.Items[i] as XmlSchemaAll;

                if (childElement != null)
                {
                    parameters.Add(new Tuple<string, string, string>(childElement.Name, childElement.SchemaTypeName.Name, parentName));
                }
                else
                {                       
                    List<Tuple<string, string, string>> moreparams = OutputElements(choice.Items[i] as XmlSchemaParticle, parentName);
                    if (moreparams != null && moreparams.Count != 0)
                    {
                        parameters.AddRange(moreparams);
                    }
                }

            }
            return parameters;
        }
        else if (all != null)
        {
            for (int i = 0; i < all.Items.Count; i++)
            {
                XmlSchemaElement childElement = all.Items[i] as XmlSchemaElement;
                XmlSchemaSequence innerSequence = all.Items[i] as XmlSchemaSequence;
                XmlSchemaChoice innerChoice = all.Items[i] as XmlSchemaChoice;
                XmlSchemaAll innerAll = all.Items[i] as XmlSchemaAll;

                if (childElement != null)
                {
                    parameters.Add(new Tuple<string, string, string>(childElement.Name, childElement.SchemaTypeName.Name, parentName));
                }
                else
                {
                    List<Tuple<string, string, string>> moreparams = OutputElements(all.Items[i] as XmlSchemaParticle, parentName);
                    if (moreparams != null && moreparams.Count != 0)
                    {
                        parameters.AddRange(moreparams);
                    }
                }
            }
            return parameters;
        }
        return parameters;
    }

Also I am passing the parent name of an element, to the parameter(s),to know where to attach it later when I create the envelope for calling the method.
 

Latest posts

Back
Top Bottom