Search code examples
c#asp.netwcfsoapwsdl

How should WSDL be structured?


As I am new to WSDL, WCF and SOAP, I have no real clue how I should structure the WSDL.

My problem right now is that when a user logs in using their username//password, the server should respond with data owned by the user. Lets say the data that wants to be sent back are:

  • MatterID
  • MatterTitle
  • MatterText
  • MatterDate

The problem is that each user can own more than 1 matter and my problem is that I have no idea how to parse more than the first Matter that the server send as response. My WSDL is structured something like this:

IN:

  • username
  • password

OUT:

  • int MatterID
  • str MatterTitle
  • str MatterText
  • int MatterDate

Am I doing it wrong? Should I respond with a list instead containing all the data? Or is there a way to loop through a response?


Solution

  • If you have an array of data to return, you better define a list in the WSDL (the types section) like so:

     <wsdl:types>
        <s:schema xmlns:s="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost/SampleService" elementFormDefault="unqualified" attributeFormDefault="unqualified">
    
            <s:complexType name="MatterItemType"> <!-- List Item -->
                <s:sequence>
                    <s:element name="MatterID" type="s:integer" minOccurs="1" maxOccurs="1"/>
                    <s:element name="MatterTitle" type="s:string" minOccurs="1" maxOccurs="1"/> 
                    <s:element name="MatterText" type="s:string" minOccurs="1" maxOccurs="1"/>
                    <s:element name="MatterDate" type="s:integer" minOccurs="1" maxOccurs="1"/>                      
                </s:sequence>
            </s:complexType>
    
            <s:complexType name="MatterListType"> <!-- List -->
                <s:sequence>
                    <s:element name="MatterItem" type="tns:MatterItemType" minOccurs="0" maxOccurs="unbounded"/>
                </s:sequence>
            </s:complexType>
    
            <!-- Request and Response -->
    
            <s:element name="SampleRequest">
                    <s:complexType>
                    <s:sequence>           
                        <s:element name="username" type="s:string" minOccurs="1" maxOccurs="1"/>
                        <s:element name="password" type="s:string" minOccurs="1" maxOccurs="1"/>                                
                    </s:sequence>
                </s:complexType>
            </s:element>
    
            <s:element name="SampleResponse">
                <s:complexType>
                    <s:sequence>                    
                        <s:element name="MatterList" type="tns:MatterListType" minOccurs="1" maxOccurs="1"/>            
                    </s:sequence>
                </s:complexType>
            </s:element>    
    
        </s:schema>
    </wsdl:types>   
    

    The Response always contains a MatterList element which is of MatterListType. The MatterListType contains from 0 to N MatterItem items defined in the MatterItemType.

    The response will be structured something like this (not including SOAP envelope, namespaces, etc, just for illustration of the structure):

    <SampleResponse>
        <MatterList>
            <MatterItem>
                <MatterID>1</MatterID>
                <MatterTitle>Title1</MatterTitle>
                <MatterText>Text1</MatterText>
                <MatterDate>1</MatterDate>
            </MatterItem>
            <MatterItem>
                <MatterID>2</MatterID>
                <MatterTitle>Title2</MatterTitle>
                <MatterText>Text2</MatterText>
                <MatterDate>2</MatterDate>
            </MatterItem>
        </MatterList>
    </SampleResponse>
    

    Let me know if you need more help in the comments.