Craig_Muckleston
asked on
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:
<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.10 4", "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.InvalidOperationExc eption: The type System.Collections.ArrayLi st may not be used in this context.
Source Error:
Line 40: <System.Web.Services.Proto cols.SoapD ocumentMet hodAttribu te("http://tempuri.org/GenericJobRequest/SendJob/InsertJob", RequestNamespace:="http://tempuri.org/GenericJobRequest/SendJob", ResponseNamespace:="http://tempuri.org/GenericJobRequest/SendJob", Use:=System.Web.Services.D escription .SoapBindi ngUse.Lite ral, ParameterStyle:=System.Web .Services. Protocols. SoapParame terStyle.W rapped)> _
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\te stbed\Web References\GenericJobInser t\Referenc e.vb Line: 42
Stack Trace:
[InvalidOperationException : The type System.Collections.ArrayLi st may not be used in this context.]
System.Xml.Serialization.X mlSerializ ationWrite r.WriteTyp edPrimitiv e(String name, String ns, Object o, Boolean xsiType)
Microsoft.Xml.Serializatio n.Generate dAssembly. XmlSeriali zationWrit er1.Write1 _Object(St ring n, String ns, Object o, Boolean isNullable, Boolean needType) +238
Microsoft.Xml.Serializatio n.Generate dAssembly. XmlSeriali zationWrit er1.Write2 _InsertJob (Object[] p) +173
[InvalidOperationException : There was an error generating the XML document.]
System.Xml.Serialization.X mlSerializ er.Seriali ze(XmlWrit er xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
System.Xml.Serialization.X mlSerializ er.Seriali ze(XmlWrit er xmlWriter, Object o, XmlSerializerNamespaces namespaces)
System.Web.Services.Protoc ols.SoapHt tpClientPr otocol.Ser ialize(Soa pClientMes sage message)
System.Web.Services.Protoc ols.SoapHt tpClientPr otocol.Inv oke(String methodName, Object[] parameters)
testbed.GenericJobInsert.S endJob.Ins ertJob(Str ing userip, String jobcode, Object param) in C:\Inetpub\wwwroot\test\te stbed\Web References\GenericJobInser t\Referenc e.vb:42
testbed.index.btnJobInsert _Click(Obj ect sender, EventArgs e) in C:\Inetpub\wwwroot\test\te stbed\inde x.aspx.vb: 129
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +108
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +57
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +33
System.Web.UI.Page.Process RequestMai n() +1292
Any ideas?
<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.10
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.InvalidOperationExc
Source Error:
Line 40: <System.Web.Services.Proto
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\te
Stack Trace:
[InvalidOperationException
System.Xml.Serialization.X
Microsoft.Xml.Serializatio
Microsoft.Xml.Serializatio
[InvalidOperationException
System.Xml.Serialization.X
System.Xml.Serialization.X
System.Web.Services.Protoc
System.Web.Services.Protoc
testbed.GenericJobInsert.S
testbed.index.btnJobInsert
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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"})
<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"})
ASKER
Brilliant - thanks. I was having a moment and didn;t notice that I'd missed the () after the ByVal param() as String...
ASKER
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.10
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