我对序列化完全不熟悉,非常感谢任何帮助。
我在通过WSDL.exe创建的代理类中收到的响应消息反序列化时遇到问题。我认为问题在于我使用的是XmlArrayItem,它内嵌了项目。
而不是得到:
<results xmlns="urn:partner.soap.company.com">
<result>
<created>false</created>
<id>0018000000ZqV8DAAV</id>
<success>true</success>
</result>
<result>
<created>false</created>
<id>0018000000ZqVMAAA3</id>
<success>true</success>
</result>
</results>
我在代码中收到以下内容:
created(0):false
id(0): false 0018000000ZqV8DAAV
success(0):false 0018000000ZqV8DAAVtrue
created(1):false 0018000000ZqV8DAAVtruefalse
id(1): false 0018000000ZqV8DAAVtruefalse0018000000ZqVMAAA3
success(1): false 0018000000ZqV8DAAVtruefalse0018000000ZqVMAAA3true
似乎响应只是在不清除之前发生的任何事情的情况下继续附加消息的下一部分。
以下是调用Web服务的主要功能:
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use:=System.Web.Services.Description.SoapBindingUse.Literal, _
ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Bare)> _
Public Function Provide_Service(<System.Xml.Serialization.XmlElement([Namespace]:="http://www.company.com/connectors/request/129/")> _
ByVal USIUpdates As USIUpdates) As _
<System.Xml.Serialization.XmlArray("results", IsNullable:=False, [Namespace]:="urn:partner.soap.sforce.com"), _
System.Xml.Serialization.XmlArrayItem("result", IsNullable:=False)> UpsertResult()
Dim results() As Object = Me.Invoke("Provide_Service", New Object() {USIUpdates})
Return CType(results(0), UpsertResult())
End Function
这是生成响应的类:
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:partner.soap.company.com")> _
Partial Public Class UpsertResult
'Public ReturnResponseItems As [ResponseItems]
Private createdField As String
Private errorsField() As [Error]
Private idField As String
Private successField As String
'''<remarks/>
Public Property created() As String
Get
Return Me.createdField
End Get
Set(ByVal value As String)
Me.createdField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("errors")> _
Public Property errors() As [Error]()
Get
Return Me.errorsField
End Get
Set(ByVal value As [Error]())
Me.errorsField = value
End Set
End Property
'''<remarks/>
<XmlElementAttribute(isnullable:=True)> _
Public Property id() As String
Get
Return Me.idField
End Get
Set(ByVal value As String)
Me.idField = value
End Set
End Property
'''<remarks/>
Public Property success() As String
Get
Return Me.successField
End Get
Set(ByVal value As String)
Me.successField = value
End Set
End Property
End Class
如果有任何关于如何处理此事的想法或建议,我将不胜感激。
答案 0 :(得分:0)
如果其他人有这个问题,这是解决方案。出于某种原因,当运行WSDL.exe时,XMLArrayItemAttribute没有正确指向包含其中的数组的类。
因此,需要将以下内容添加到main函数中的XMLArrayItemAttribute:
Type:=GetType(UpsertResult)
然后看起来像这样:
System.Xml.Serialization.XmlArrayItemAttribute("result", IsNullable:=False, Type:=GetType(UpsertResult))