PRB: XML Web Service Created with ASP.NET Does Not Support Multidimensional Arrays (316273)



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework 1.1)
  • Microsoft Web Services (included with the .NET Framework 1.1)
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft ASP.NET (included with the .NET Framework) 1.0
  • Microsoft Web Services (included with the .NET Framework) 1.0

This article was previously published under Q316273

SYMPTOMS

When you try to obtain a Web Services Description Language (WSDL) document from a Web service by using a Web service method that contains a return type or parameter type that is a multidimensional array, you receive the following HTML error message:
Cannot serialize object of type System.String[,]. Multidimensional arrays are not supported.
An exception is generated if you call the Web Service.
XML Web services that are created with ASP.NET do not support multidimensional arrays.

RESOLUTION

Instead of using multidimensional arrays, use the following code to specify an array of arrays (in other words, a jagged array):
Visual C# .NET example:

[WebMethod]
public string[][] ReturnMultiDimArray() 
{
  string [] y = {"ab","cd"};
  string [] z = {"ef","gh"};			
  string [][] x = {y,z};			
  return x;
}

Visual Basic .NET example:

<WebMethod> Public Function ReturnMultiDimArray() As String()()
  Dim y As String()
  Dim z As String()
  Dim x As String()() = New String()() {y, z}
  Return x
End Function
				

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create an ASP.NET Web Service project.
  2. Paste the following Web service method in WebService1.asmx.cs:
       Visual C# .NET example:
    
       [WebMethod]
       public string[,] ReturnMultiDimArray()
       {
        string [,] x = new string[,] {{"ab"},{"cd"}} ; 
        return x;
       }
    
       Visual Basic .NET example:
    
       <WebMethod> Public Function ReturnMultiDimArray() As String(,)
        Dim x As String(,) = New String(,) {{}, {}}
        Return x
       End Function
    						
  3. Build the Web Service.
  4. In Solution Explorer, right-click Service1.asmx.
  5. Try to obtain a WSDL document from a Web Service.

Modification Type:MinorLast Reviewed:2/11/2004
Keywords:kbprb KB316273 kbAudDeveloper