Question : Error sending ArrayList to Web Service

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:

_
    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:         cols.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?

Answer : Error sending ArrayList to Web Service

Can you change your web service from

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

To:

_
    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)
Random Solutions  
 
programming4us programming4us