1

I'm consuming a web service and I have this From the wsdl:

<xs:complexType name="Person">
    <xs:sequence>          
      <xs:element minOccurs="0" maxOccurs="unbounded" name="PersonAddresses" type="ns:PersonAddress" />
    </xs:sequence>
</xs:complexType>

from the xsd:

<!--Complex Type for PersonAddress-->
<xs:complexType name="PersonAddress">
    <xs:sequence>
        <xs:element name="Address" type="Address" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<!--Complex Type for Address-->
<xs:complexType name="Address">
    <xs:sequence>
        <xs:element name="Addr1" type="xs:string" minOccurs="0" maxOccurs="1"/>
        <xs:element name="Addr2" type="xs:string" minOccurs="0" maxOccurs="1"/>
        <xs:element name="City" type="xs:string" minOccurs="0" maxOccurs="1"/>
        <xs:element name="State" type="xs:string" minOccurs="0" maxOccurs="1"/>
        <xs:element name="Zip" type="xs:string" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

Using the generated proxy, I create an Collection of PersonAddress and add Address objects to it.

...
var convertedAddresses = new PersonAddress[addressesToCounvert.Count];
for (int i = 0; i < addresses.Count; i++)
{
    convertedAddresses[i] = ConvertAddress(addresses[i]);
}
person.PersonAddresses = convertedAddresses;
...

When I submit the request, it looks like this

<PersonAddress>
    <Address>
        ...
    </Address>
</PersonAddress>
<PersonAddress>
    <Address>
        ...
    </Address>
</PersonAddress>

So what am I doing wrong..the needed format would be

<PersonAddress>
    <Address>
        ...
    </Address>
    <Address>
        ...
    </Address>
</PersonAddress>

Thanks for any input

2
  • Can you change maxOccurs="1" to maxOccurs="unbounded" for PersonAddress/Address in the schema? Commented Dec 14, 2012 at 20:56
  • thanks! This appears to be the issue. Commented Dec 14, 2012 at 21:12

1 Answer 1

1

As far as I can tell, the output you're getting matches the WSDL/XSD definitions. Based on the WSDL, a <Person> element can contain multiple <PersonAddress> elements. Based on the XSD, a <PersonAddress> element can contain 0 or 1 <Address> elements. Valid contstructions using the information provided would be:

<Person>
 <PersonAddress>
  <Address>
    ...
  </Address>
 </PersonAddress>
</Person>
<Person>
 <PersonAddress>
  <Address>
      ...
  </Address>
 </PersonAddress>
 <PersonAddress>
  <Address>
      ...
  </Address>
 <PersonAddress>
</Person>

Please also note that there is an inconsistency in the spelling of <PersonAddress>. In the WSDL code you provided a <Person> element is defined to contain 0 to many <PersonAddresses> elements (note the pluralization of "Addresses"). I assumed, for the purposes of this answer, that this was just a typo and that <PersonAddresses> should really have been spelled as <PersonAddress> in the WSDL. I wanted to make sure to point this out in case the problem is simply that you're using the wrong object (i.e. maybe there is a <PersonAddresses> complex type that allows 1 to many <Address> elements within it)

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! Changing to allow 1 to many appears to be the issue. I need to get the provider of the service to change it if they want the request format to change.
I don't think I agree with that approach. Why does the provider of the service need to change something? What data requirement isn't satisfied with the current WSDL/XSD?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.