Need maxOccurs="unbounded" in WCF Data Contract Needs

I'm trying to mock an existing Web Service in another environment for testing purposes and have run into a road block.

I'm attempting to create this Mock Service in WCF

The service i'm mocking (which is not dev'd in WCF) has an entity with this type defintion:

<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="dog" nillable="true" type="xs:string"/>

</xs:sequence>

Notice the maxOccurs="unbounded" the message itself looks something like this:

<dog>1</dog>
<dog>2</dog>

But i can't figure out how to define my DataContract to deal with this. I assumed just using an array type like:

    [DataContract]
    public class P56040Input
    {
        [DataMember]
        public string[] dog { get; set; }


    }

would correspond, but it does something unexpected with a new type (arrayofstring):

<xs:sequence>
<xs:element xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="dog" nillable="true" type="q1:ArrayOfstring"/>
</xs:sequence>

Is this even possible to mock in WCF?

Answers


if you go to the ArrayOfString definition you will see it has maxOccurs=“unbounded”. So what you see here is just the wrapper type wcf generated. In order not to generate such type you would need to use xml serializer and not data contract. The definition will look like this:

[System.Xml.Serialization.XmlElementAttribute("dog")]
public string[] dog  {get; set;}

how did I know? all you need to do is "add web reference" to the wsdl (so that the client proxy is generated). Then take a look at the relevant proxy part to see the attributes on top of the type. You could do the same with "add service reference" which uses by default the data contract and see that it generated what you used, which is not exactly the same as what you need.


Need Your Help

CSS: Nested elements without explicit width and word wrap

css html clear css-float word-wrap

I am trying to position a caption below an image without explicit knowledge of the images' width. I would like the caption to extend to the full image width, but not to stretch the parent elements'...