0

我想将数据提供给一个代理,该代理创建一个SOAP XML请求,格式如下:

<dat:MusicCollection>
           <!--Zero or more repetitions:-->
           <dat:Song>
              <dat:songUserkey>TakemeHome</dat:songUserkey>
           </dat:Song>
</dat:MusicCollection>

我已经编写了文件来调用服务并提供如下详细信息:

dim ucizi1 as SongRequest 'this is the request class in the proxy
dim Songs as Song = New Song
Songs.songUserKey = "TakeMeHome"
dim ucz
ucz = Songs.SongUserKey
ucizi1.SongCollection.Add(ucz)

MusicCollection 类如下:

<System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"),  _
 System.Runtime.Serialization.CollectionDataContractAttribute(Name:="ProductCollection", [Namespace]:="http://ucizi.Musicservice/DataContracts", ItemName:="Song")>  _
Public Class SongCollection
    Inherits System.Collections.Generic.List(Of ucizi.Music.DataContracts.Song)
End Class

歌曲类如下:

<System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"),  _
 System.Runtime.Serialization.DataContractAttribute(Name:="Product", [Namespace]:="http://Ucizi.Music/DataContracts")>  _
Partial Public Class Product
    Inherits Object
    Implements System.Runtime.Serialization.IExtensibleDataObject

    Private extensionDataField As System.Runtime.Serialization.ExtensionDataObject

    Private SongUserkeyField As String

    Public Property ExtensionData() As System.Runtime.Serialization.ExtensionDataObject Implements System.Runtime.Serialization.IExtensibleDataObject.ExtensionData
        Get
            Return Me.extensionDataField
        End Get
        Set
            Me.extensionDataField = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=true)>  _
    Public Property SongUserkey() As String
        Get
            Return Me.SongUserkeyField
        End Get
        Set
            Me.SongUserkeyField = value
        End Set
    End Property
End Class

但是,当我运行此代码时,出现错误:无法将类型为“system.string”的对象转换为类型“ucizi.music.DataContracts.Song”。

我看不出这个错误是从哪里来的,有人可以帮助我并告诉我如何纠正这个错误。

4

2 回答 2

0

排队

Songs.songUserKey = "TakeMeHome"
dim ucz
ucz = Songs.SongUserKey
ucizi.SongCollection.Add(ucz)

你设置uczSongUserKey- 这是字符串。

然后,将它添加到集合SongCollection

Public Class SongCollection
    Inherits System.Collections.Generic.List(Of ucizi.Music.DataContracts.Song)
End Class

这是预期的Song

于 2013-04-16T18:56:30.410 回答
0

在Songs.songUserKey = "TakeMeHome"之后添加以下代码

dim ucizi2 as songCollection
ucizi2.Add(song)
ucizi1.songcollection = ucizi2

这样就顺利解决了问题。你们让我大开眼界。

于 2013-04-17T14:41:10.090 回答