Reputation: 2213
I have a WebService defined as this:
<WebMethod(Description:="Retrieve a list of account profiles.")> _
<System.Web.Services.Protocols.SoapHeader("MyHeader")> _
Public Function RetrieveAccountProfile(<XmlElement(IsNullable:=True, Type:=GetType(WSRetrieveAccountProfile))> ByVal myAccount As WSRetrieveAccountProfile) As <XmlElement(IsNullable:=True)> WSResponseRetrieveAccountProfile
...
The class I am passing as an input parameter WSRetrieveAccountProfile
is defined like this:
<Serializable()> _
<XmlType(Namespace:="http://mynamespace/", TypeName:="WSRetrieveAccountProfile")> _
Public Class WSRetrieveAccountProfile
<XmlElement(IsNullable:=False)> Public accountNumber As List(Of Integer)
Public Sub New()
End Sub
Public Function Validate() As Boolean
'Validations here
Return True
End Function
End Class
The issue: I consume web-service and I am working on the client side where I am trying to declare an object of type WSRetrieveAccountProfile
so I can pass it as an input parameter when calling the web-service, but I get compilation error - it cannot recognize the type.
After checking Reference.vb I notice that an input parameter for the function is a plain array of Integer ByVal myAccount() As Integer
. Now, if I add another variable to the WSRetrieveAccountProfile
class definition the ByVal myAccount() As Integer
suddenly changes to ByVal myAccount As WSRetrieveAccountProfile
and problem is solved.
How do I solve this WITHOUT adding an unnecessary variable? I tried with XmlType attribute with no luck.
* UPDATE * This definition works:
<Serializable()> _
<XmlType(Namespace:="http://mynamespace/", TypeName:="WSRetrieveAccountProfile")> _
Public Class WSRetrieveAccountProfile
<XmlElement(IsNullable:=False)> Public accountNumber As List(Of Integer)
<XmlElement(IsNullable:=True)> Public TEST As String
Public Sub New()
End Sub
Public Function Validate() As Boolean
'Validations here
Return True
End Function
End Class
* UPDATE - SOLUTION *
If I change
<XmlElement(IsNullable:=False)> Public accountNumber As List(Of Integer)
to
<XmlArray(IsNullable:=True)> Public accountNumber As List(Of Integer)
then the proxy is generated properly and I no longer have an issue.
Upvotes: 2
Views: 1128
Reputation: 2213
Change
<XmlElement(IsNullable:=False)> Public accountNumber As List(Of Integer)
to
<XmlArray(IsNullable:=True)> Public accountNumber As List(Of Integer)
to fix proxy generation.
Upvotes: 1