我想将数据提供给代理,该代理会创建一个格式如下的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'。
我无法看到这个错误的来源,有些人可以帮助我,并建议我如何纠正这个错误。
答案 0 :(得分:0)
在行
Songs.songUserKey = "TakeMeHome"
dim ucz
ucz = Songs.SongUserKey
ucizi.SongCollection.Add(ucz)
您将ucz
设置为SongUserKey
- 这是字符串。
然后,将其添加到集合 SongCollection
Public Class SongCollection
Inherits System.Collections.Generic.List(Of ucizi.Music.DataContracts.Song)
End Class
预期 Song
答案 1 :(得分:0)
在 Songs.songUserKey =“TakeMeHome”后添加以下代码
dim ucizi2 as songCollection
ucizi2.Add(song)
ucizi1.songcollection = ucizi2
这使问题顺利排序。你们睁开眼睛。