You receive an "unspecified client error" error message when you run a Visual Basic for Applications program

Article translations Article translations
Article ID: 840925 - View products that this article applies to.
Expand all | Collapse all

On This Page

Symptoms

When you run a Microsoft Visual Basic for Applications (VBA) program that calls an XML Web service method, you may receive the following error message:
Run-time error '-2147221504 (80040000)':

Client:Unspecified client error.

Cause

An ArrayList object may contain elements of any data type. Therefore, when the Microsoft .NET Framework generates Web Services Description Language (WSDL) code that corresponds to an XML Web service method that returns an ArrayList object, the WSDL code does not specify the data type of the element that corresponds to the ArrayList object. When you try to call this XML Web service method, the Microsoft SOAP Toolkit cannot recognize the data type of the element that corresponds to the ArrayList object. Therefore, the SOAP Toolkit raises an error.

Workaround

In the WSDL code that corresponds to the XML Web service method, specify the data type of the element that corresponds to the ArrayList object as anyType. To do this, follow these steps:
  1. Locate the WSDL code that corresponds to your XML Web service, and then save this code as a WSDL contract file on your local computer.
  2. In the WSDL contract file, locate the following WSDL code.
    <s:complexType name="ArrayOfAnyType">
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true" /> 
        </s:sequence>
    </s:complexType>
  3. Replace the code that you located in step 2 with the following code.
    <s:complexType name="ArrayOfAnyType">
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true" type="s:anyType"/> 
        </s:sequence>
    </s:complexType>
  4. Save and then close the WSDL contract file.
  5. In the proxy class file for the XML Web service, replace the existing path of the WSDL contract information with the path of the WSDL contract file that you saved on your local computer in step 4.

Status

This behavior is by design.

More information

Steps to reproduce the problem

  1. Install the correct version of the Web Services Toolkit:
  2. Create an XML Web service that contains an XML Web service method that returns an ArrayList object:
    1. Start Microsoft Visual Studio .NET.
    2. Use Microsoft Visual Basic .NET to create a Microsoft ASP.NET Web Service project. Name the project MyService. By default, the Service1.asmx file is created.
    3. In the code view of the Service1.asmx file, locate the following code.
      End Class
    4. Add the following code before the code that you located in step c:
      <WebMethod()> _
      Public Function GetArrayList() As ArrayList
          Dim MyArrayList As New ArrayList
          MyArrayList.Add("Blue")
          MyArrayList.Add("Green")
          MyArrayList.Add("Red")
          Return MyArrayList
      End Function
    5. Build the solution to create the Service1 XML Web service.
  3. Start Microsoft Excel.
  4. On the Tools menu, point to Macro, and then click Visual Basic Editor. The VBA editor appears.
  5. On the Tools menu, click Web Service References.
    • If you are using Office 2003, the Microsoft Office 2003 Web Services Toolkit dialog box appears.
    • If you are using Office XP or Office 2000, the Web Service References Tool 2.0 dialog box appears.
  6. Click Web Service URL.
  7. In the URL box, type the URL of the WSDL code that corresponds to the Service1 XML Web service. For example, if the URL of the Service1 XML Web service is http://MyServer/MyService/Service1.asmx, type http://MyServer/MyService/Service1.asmx?wsdl in the URL box.
  8. Click Search. The Service1 XML Web service appears in the Search Results box.
  9. In the Search Results box, click to select the Service1 check box, and then click Add. A class module that is named clsws_Service1 is added to your VBA project.
  10. In Project Explorer, right-click VBAProject (Book1), point to Insert, and then click UserForm. The UserForm1 user form is added to the VBA project.
  11. Add a command button to the UserForm1 user form. By default, the CommandButton1 command button is added to the UserForm1 user form.
  12. Double-click CommandButton1 to open the code view of the UserForm1 user form.
  13. Add the following code to the CommandButton1_Click event handler.
    Dim objArrayList As Variant
    Dim WebService As New clsws_Service1
    Dim Item As Variant
    
    objArrayList = WebService.wsm_GetArrayList
    
    For Each Item In objArrayList
    MsgBox Item
    Next
  14. On the Run menu, click Run Sub/UserForm. The UserForm1 user form appears.
  15. Click CommandButton1.
The problem that is mentioned in the "Symptoms" section occurs.

References

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

What's new in the Microsoft Office 2003 Web Services Toolkit
http://msdn2.microsoft.com/en-us/library/aa192537(office.11).aspx

Microsoft Office XP Web Services Toolkit 2.0
http://msdn2.microsoft.com/en-us/library/aa140324(office.10).aspx

Programming the Web with XML Web services
http://msdn2.microsoft.com/en-us/library/9t8zkaxa(VS.80).aspx

Understanding WSDL
http://msdn2.microsoft.com/en-us/library/ms996486.aspx

ArrayList class
http://msdn2.microsoft.com/en-us/library/system.collections.arraylist(vs.71).aspx

Understanding SOAP
http://msdn2.microsoft.com/en-us/library/ms995800.aspx

SOAP Toolkit
http://msdn2.microsoft.com/en-us/webservices/aa740662.aspx

Properties

Article ID: 840925 - Last Review: September 6, 2012 - Revision: 2.0
Applies to
  • Microsoft Visual Basic for Applications 6.0
Keywords: 
kbxml kbwebclasses kbclientserver kbclientprotocols kbclient kbtoolkit kberrmsg kbwebservices kbprb KB840925

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com