嵌套项目的 XmlArrayItem 反序列化错误

发布于 2024-08-09 12:51:34 字数 3423 浏览 3 评论 0原文

我对序列化完全陌生,非常感谢任何帮助。

我在反序列化从通过 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

如果您有任何有关如何处理此问题的想法或建议,我将不胜感激。

I am totally new to serialization and would greatly appreciate any help.

I am having problems deserializing the response message I receive from the proxy class I created through WSDL.exe. I believe the problem lies in the fact that I am using XmlArrayItem, which has nested items within.

Instead of getting:

<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>

I am receiving the following in code:

created(0):false
id(0): false 0018000000ZqV8DAAV
success(0):false 0018000000ZqV8DAAVtrue

created(1):false 0018000000ZqV8DAAVtruefalse
id(1): false 0018000000ZqV8DAAVtruefalse0018000000ZqVMAAA3
success(1): false 0018000000ZqV8DAAVtruefalse0018000000ZqVMAAA3true

It appears as if the response just keeps appending the next part of the message without clearing out anything that has gone before.

Here is the main function that calls the web service:

 <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

And here is the class the generates the response:

<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

I would be grateful for any ideas or advice on how to handle this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲欢浪云 2024-08-16 12:51:34

如果其他人遇到这个问题,这里是解决方案。由于某种原因,当 WSDL.exe 运行时,XMLArrayItemAttribute 没有正确指向包含其中数组的类。

因此,需要将以下内容添加到主函数中的 XMLArrayItemAttribute:

Type:=GetType(UpsertResult)

,然后如下所示:

System.Xml.Serialization.XmlArrayItemAttribute("result", IsNullable:=False,类型:=GetType(UpsertResult))

In case anyone else has this problem, here is the solution. For some reason when WSDL.exe was run, the XMLArrayItemAttribute did not properly point to the class containing the arrays within.

Thus, the following needed to be added to XMLArrayItemAttribute in the main function:

Type:=GetType(UpsertResult)

which then looks like this:

System.Xml.Serialization.XmlArrayItemAttribute("result", IsNullable:=False, Type:=GetType(UpsertResult))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文