C#Web服务中类似PHP的数组

I have a webservice written in PHP and a client written in Java which work together. But now, I have to replace the PHP-webservice by a C#-webservice and I can't change the Java-Client. I already got a solution, that works, apart from one last step. One of the response-parameters has to be an array. In PHP the response was:

<elements SOAP-ENC:arrayType="xsd:string[2]" xsi:type="ns1:stringArray">
    <item xsi:type="xsd:string">ABC</item>
    <item xsi:type="xsd:string">XYZ</item>
</elements>

If there is only one element in the array, the response from C# looks like this and works:

<elements>ABC</elements>

But if there are more elements in the array, the response looks like:

<elements>
    <string>ABC</string>
    <string>XYZ</string>
</elements>

And the client throws an error.

Is there a way, to create an array in C#, which behaves like an array in PHP?


The C#-code is:

[System.Xml.Serialization.SoapElementAttribute(IsNullable = true)]
public string[] elements {
    get {
        publicationsField = new string[] { "ABC", "XYZ" };
        return publicationsField;
    }
    set {
        this.publicationsField = value;
    }
}

I suppose you could attempt to parse the response as XML and check if <string> is set.

If it is, you'd parse all of them in a loop and add them to an array. Otherwise, you'd create an array with one element, that element being the value of <elements>.

(Edit: Here's some pseudo-code as per OP's request for an idea on how to do this.)

xml = ParseXML(GetXML())
elements = xml[elements]

for each element in elements
    if sub element named string exists
        // it exists
    else
        // nope