title: How to return a multi-dimensional array from a web service method?
body: <pre><code>[WebMethod]
  public  Object  GetAllItemsArray() 
  {
          FoodCityData.ShoppingBuddyEntities fdContext = new FoodCityData.ShoppingBuddyEntities();
  
          IQueryable&lt;Item&gt; Query =
         from c in fdContext.Item
         select c;
  
          List&lt;Item&gt; AllfNames = Query.ToList();
          int arrayZise = AllfNames.Count;
          String[,] xx = new String[arrayZise,2];
          int i = 0;
          int j = 0;
          foreach(Item x in AllfNames)
          {
  
                  xx[i,0] = x.ItemName.ToString();
                  xx[i, 1] = x.ItemPrice.ToString();
                  i++;
          }
  
           return (Object)xx;
      }
  </code></pre>
  
  <p>I want to return a multi-dimensional array from this web service how do I do it?</p>
  
  <p>This code gives a error</p>
  
  <p>Actually this web service is calling from android application that's why I return this data as a multi-dimensional array..</p>
  
  <p><strong>Error IS:</strong></p>
  
  <pre><code>System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.NotSupportedException: Cannot serialize object of type System.String[,]. Multidimensional arrays are not supported.
     at System.Xml.Serialization.TypeDesc.CheckSupported()
     at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
     at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
     at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
     at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5_anyType(Object o)
     at Microsoft.Xml.Serialization.GeneratedAssembly.ObjectSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
     --- End of inner exception stack trace ---
     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
     at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
     at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
     at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
     at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
     at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
     at System.Web.Services.Protocols.WebServiceHandler.Invoke()
  </code></pre>