[WebMethod]
public Object GetAllItemsArray()
{
FoodCityData.ShoppingBuddyEntities fdContext = new FoodCityData.ShoppingBuddyEntities();
IQueryable<Item> Query =
from c in fdContext.Item
select c;
List<Item> 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;
}
この Web サービスから多次元配列を返したいのですが、どうすればよいですか?
このコードはエラーを返します
実際、この Web サービスは Android アプリケーションから呼び出しているため、このデータを多次元配列として返します。
エラーは:
System.InvalidOperationException: There was an error generating the XML document. ---> 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()