2

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.

6
  • Can you show the definition of the WSRetrieveAccountProfile class that works and the one that doesn't? Commented Sep 26, 2012 at 18:07
  • done: the cnage is simply adding a string variable. I don't do anything with it, but it seems to fix the issue I am having. I am starting to think that maybe its the Microsoft Visual Web Developer 2010 Express that is causing it because there is no difference in WSDL's, other then additional variable definition. Commented Sep 26, 2012 at 18:12
  • 2
    Interesting, so the only public property of the class, when it doesn't work, is a list of integers, so the compiler thinks it will be clever and simplifies it down to an array of integers rather than creating a custom type... Commented Sep 26, 2012 at 18:18
  • Yes, its seems that way. When I consume the webservice, the reference.vb (thats the proxy, right?) gives me an array of integers in the first scenario, and an object of type WSRetrieveAccountProfile in the second scenario with definition of latter object further down. Is there anyway to prevent VisualStudio from being "smart" like that? Commented Sep 26, 2012 at 18:22
  • In the client, are you using "Add Web Reference", or "Add Service Reference"? If you use "Add Service Reference", then you can choose whether collections should be List or Array or what. Commented Sep 26, 2012 at 18:33

1 Answer 1

1

Change

<XmlElement(IsNullable:=False)> Public accountNumber As List(Of Integer)

to

<XmlArray(IsNullable:=True)> Public accountNumber As List(Of Integer)

to fix proxy generation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.