Solved

Error sending ArrayList to Web Service

Posted on 2006-10-27
4
1,550 Views
Last Modified: 2012-06-22
I have a Web Service with a function that inserts parameters into a table. The parameters are coming from an arraylist. I have declared my web services function as:

<WebMethod()> _
    Public Function InsertJob _
    (ByVal userip As String, _
    ByVal jobcode As String, _
    ByVal param As Object) As Object

From my client page I instantiate the service and pass the params through as follows:

        ' create and initialise a new ArrayList.
        Dim paramList As New ArrayList
        paramList.Add("here")
        paramList.Add("there")
        paramList.Add("everywhere")

        Dim svc As New GenericJobInsert.SendJob
        svc.InsertJob("10.249.3.104", "web_svc_test", paramList)

If I use the same function (from the web service) in my client pagem everything runs fine, but when I try to use the web service version, I get the following error:

Exception Details: System.InvalidOperationException: The type System.Collections.ArrayList may not be used in this context.

Source Error:


Line 40:         <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GenericJobRequest/SendJob/InsertJob", RequestNamespace:="http://tempuri.org/GenericJobRequest/SendJob", ResponseNamespace:="http://tempuri.org/GenericJobRequest/SendJob", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _
Line 41:         Public Function InsertJob(ByVal userip As String, ByVal jobcode As String, ByVal param As Object) As Object()
Line 42:             Dim results() As Object = Me.Invoke("InsertJob", New Object() {userip, jobcode, param})
Line 43:             Return CType(results(0),Object())
Line 44:         End Function
 

Source File: C:\Inetpub\wwwroot\test\testbed\Web References\GenericJobInsert\Reference.vb    Line: 42

Stack Trace:


[InvalidOperationException: The type System.Collections.ArrayList may not be used in this context.]
   System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
   Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) +238
   Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_InsertJob(Object[] p) +173

[InvalidOperationException: There was an error generating the XML document.]
   System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
   System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
   System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage message)
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   testbed.GenericJobInsert.SendJob.InsertJob(String userip, String jobcode, Object param) in C:\Inetpub\wwwroot\test\testbed\Web References\GenericJobInsert\Reference.vb:42
   testbed.index.btnJobInsert_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\test\testbed\index.aspx.vb:129
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292

 Any ideas?
0
Comment
Question by:Craig_Muckleston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
xersoft earned 50 total points
ID: 17818958
Can you change your web service from

<WebMethod()> _
    Public Function InsertJob _
    (ByVal userip As String, _
    ByVal jobcode As String, _
    ByVal param As Object) As Object

To:

<WebMethod()> _
    Public Function InsertJob _
    (ByVal userip As String, _
    ByVal jobcode As String, _
    ByVal param() As String) As Object

and then call it like this:

        ' create and initialise a new ArrayList.
        Dim paramList As New ArrayList
        paramList.Add("here")
        paramList.Add("there")
        paramList.Add("everywhere")

        Dim svc As New GenericJobInsert.SendJob
        svc.InsertJob("10.249.3.104", "web_svc_test", Directcast(paramList.ToArray(gettype(string)),string()))


or in .net 2.0

        ' create and initialise a new ArrayList.
        Dim paramList As New list(of String)
        paramList.Add("here")
        paramList.Add("there")
        paramList.Add("everywhere")

        Dim svc As New GenericJobInsert.SendJob
        svc.InsertJob("10.249.3.104", "web_svc_test", paramList.ToArray)
0
 

Author Comment

by:Craig_Muckleston
ID: 17867017
Hi xersoft,

I have tride this, but when I call the web service from my page (using        

Dim svc As New GenericJobInsert.SendJob
svc.InsertJob("10.249.3.104", "web_svc_test", DirectCast(paramList.ToArray(GetType(String)), String()))

I can't compile the project because I get "Value of '1 dimensional array od String' cannot be converted to 'String'." on the above line
0
 
LVL 5

Expert Comment

by:xersoft
ID: 17867375
Check your Web method and make sure the sig is correct:

<WebMethod()> _
    Public Function InsertJob _
    (ByVal userip As String, _
    ByVal jobcode As String, _
    ByVal param() As String) As Object


In this case the byval Param() as string is very important. it must have the () after the paramater name. If you do indeed have that, make sure you update your web refference from in the app. If after updating the web method sig, and updating the refference from the app that uses the web service and it still does not work, please post the prototype (method declaration) of the web method in full. (not the body of the method)

Another thing to look at is exactly what you have stored in the array list paramList.
Could you post the code you use to fill that array list?

we need to be sure we are putting a single string in each item of the list not arrays of strings:

GOOD:
paramList.add("one")
paramList.add("two")

BAD:
paramList.add(new string() {"one", "two"})
0
 

Author Comment

by:Craig_Muckleston
ID: 17888227
Brilliant - thanks. I was having a moment and didn;t notice that I'd missed the () after the ByVal param() as String...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expression Evaluater 3 45
vb.net 1 month apart 11 39
VB.net Open video relating to control 2 29
Create simple VB.net Add-in for Excel in Office 365 2 16
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question