Vb.net 带有输入类参数的Webservice将其转换为数组
我将Web服务定义为:Vb.net 带有输入类参数的Webservice将其转换为数组,vb.net,web-services,Vb.net,Web Services,我将Web服务定义为: <WebMethod(Description:="Retrieve a list of account profiles.")> _ <System.Web.Services.Protocols.SoapHeader("MyHeader")> _ Public Function RetrieveAccountProfile(<XmlElement(IsNullable:=True, Type:=GetType(WSRetrieveAccoun
<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
...
问题:我使用web服务,在客户端工作,我试图声明类型为WSRetrieveAccountProfile
的对象,以便在调用web服务时将其作为输入参数传递,但出现编译错误-它无法识别该类型
在检查Reference.vb之后,我注意到该函数的输入参数是一个整数的普通数组ByVal myAccount()作为整数。现在,如果我在WSRetrieveAccountProfile
类定义中添加另一个变量,则ByVal myAccount()作为整数
突然变为ByVal myAccount作为WSRetrieveAccountProfile
,问题就解决了
如何在不添加不必要变量的情况下解决此问题?我尝试使用XmlType属性,但没有成功
*更新*
这一定义适用于:
<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
_
_
公共类WSRetrieveAccountProfile
公共帐号作为列表(整数)
作为字符串的公共测试
公共分新()
端接头
公共函数Validate()为布尔值
“这里是验证
返回真值
端函数
末级
*更新-解决方案*
如果我改变
Public accountNumber作为列表(整数)
到
Public accountNumber作为列表(整数)
然后代理正确生成,我不再有问题。更改
Public accountNumber作为列表(整数)
到
Public accountNumber作为列表(整数)
修复代理生成。能否显示WSRetrieveAccountProfile类有效和无效的定义?完成:cnage只是添加一个字符串变量。我没有做任何事情,但它似乎解决了我的问题。我开始认为,可能是Microsoft Visual Web Developer 2010 Express导致了这种情况,因为WSDL与其他变量定义没有区别。有趣的是,当类不起作用时,它唯一的公共属性是整数列表,因此,编译器认为它会很聪明,并将其简化为整数数组,而不是创建自定义类型……是的,似乎是这样。当我使用webservice时,reference.vb(那是代理,对吗?)在第一个场景中为我提供了一个整数数组,在第二个场景中为我提供了一个类型为WSRetrieveAccountProfile
的对象,后面一个对象的定义进一步向下。是否有任何方法可以防止VisualStudio如此“聪明”?在客户端中,您是使用“添加Web引用”还是“添加服务引用”?如果使用“添加服务引用”,则可以选择集合是列表还是数组,或者是什么。
<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