How to Declare Complex Nested C# Type for Web Service

Posted by TheArtTrooper on Stack Overflow See other posts from Stack Overflow or by TheArtTrooper
Published on 2009-10-28T22:29:34Z Indexed on 2010/06/07 1:02 UTC
Read the original article Hit count: 278

Filed under:
|

I would like to create a service that accepts a complex nested type. In a sample asmx file I created:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ServiceNest : System.Web.Services.WebService
{
   public class Block
   {
      [XmlElement(IsNullable = false)]
      public int number;
   }

   public class Cell
   {
      [XmlElement(IsNullable = false)]
      public Block block;
   }

   public class Head
   {
      [XmlElement(IsNullable = false)]
      public Cell cell;
   }

   public class Nest
   {
      public Head head;
   }

   [WebMethod]
   public void TakeNest(Nest nest)
   {
   }

}

When I view the asmx file in IE the test page shows the example SOAP post request as:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <TakeNest xmlns="http://schemas.intellicorp.com/livecompare/">
      <nest>
        <head>
          <cell>
            <block xsi:nil="true" />
          </cell>
        </head>
      </nest>
    </TakeNest>
  </soap:Body>
</soap:Envelope>

It hasn't expanded the <block> into its number member.

Looking at the WSDL, the types all look good. So is this just a limitation of the post demo page creator?

Thanks.

© Stack Overflow or respective owner

Related posts about web-services

Related posts about asmx