Reputation: 125
I have problem with deserialize SOAP response. I get xml like: https://pastebin.com/pNFmJUzB its xml from web service
But elements from RegistryObjectList is not deserialized (statusField deserialized correctly) :
This code is generated from wsdl shared by webService provider. I used svcutil to reach it. its my code :
I run this function:
Public Function DocumentRegistry_RegistryStoredQuery(ByVal AdhocQueryRequest As AdhocQueryRequest) As AdhocQueryResponse
Dim inValue As DocumentRegistry_RegistryStoredQueryRequest = New DocumentRegistry_RegistryStoredQueryRequest()
inValue.AdhocQueryRequest = AdhocQueryRequest
Dim retVal As DocumentRegistry_RegistryStoredQueryResponse = CType(Me,ObslugaEdmIti18WSPortType).DocumentRegistry_RegistryStoredQuery(inValue)
Return retVal.AdhocQueryResponse
End Function
which return AdHocQueryResponse :
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0")> _
Partial Public Class AdhocQueryResponse
Inherits RegistryResponseType
Private registryObjectListField() As IdentifiableType
Private startIndexField As String
Private totalResultCountField As String
Public Sub New()
MyBase.New
Me.startIndexField = "0"
End Sub
'''<remarks/>
<System.Xml.Serialization.XmlArrayAttribute(Order:=0), _
System.Xml.Serialization.XmlArrayItemAttribute("Identifiable", IsNullable:=False)> _
Public Property RegistryObjectList() As IdentifiableType()
Get
Return Me.registryObjectListField
End Get
Set(value As IdentifiableType())
Me.registryObjectListField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="integer"), _
System.ComponentModel.DefaultValueAttribute("0")> _
Public Property startIndex() As String
Get
Return Me.startIndexField
End Get
Set
Me.startIndexField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="integer")> _
Public Property totalResultCount() As String
Get
Return Me.totalResultCountField
End Get
Set
Me.totalResultCountField = value
End Set
End Property
End Class
AdHocQueryResponse Should contains ExtrinsicObjects :
'''<remarks/>
<System.Xml.Serialization.XmlIncludeAttribute(GetType(RegistryObjectType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(NotificationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AdhocQueryType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(SubscriptionType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(FederationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(RegistryType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(PersonType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(UserType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(SpecificationLinkType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ServiceBindingType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ServiceType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(RegistryPackageType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(OrganizationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExtrinsicObjectType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExternalLinkType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationSchemeType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationNodeType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AuditableEventType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AssociationType1)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExternalIdentifierType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ObjectRefType)), _
System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")> _
Partial Public Class IdentifiableType
Private slotField() As SlotType1
Private idField As String
Private homeField As String
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("Slot", Order:=0)> _
Public Property Slot() As SlotType1()
Get
Return Me.slotField
End Get
Set
Me.slotField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="anyURI")> _
Public Property id() As String
Get
Return Me.idField
End Get
Set
Me.idField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="anyURI")> _
Public Property home() As String
Get
Return Me.homeField
End Get
Set
Me.homeField = value
End Set
End Property
End Class
'''<remarks/>
<System.Xml.Serialization.XmlIncludeAttribute(GetType(NotificationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AdhocQueryType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(SubscriptionType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(FederationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(RegistryType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(PersonType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(UserType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(SpecificationLinkType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ServiceBindingType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ServiceType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(RegistryPackageType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(OrganizationType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExtrinsicObjectType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExternalLinkType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationSchemeType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationNodeType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AuditableEventType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(AssociationType1)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ExternalIdentifierType)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ClassificationType)), _
System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")> _
Partial Public Class RegistryObjectType
Inherits IdentifiableType
Private nameField As InternationalStringType
Private descriptionField As InternationalStringType
Private versionInfoField As VersionInfoType
Private classificationField() As ClassificationType
Private externalIdentifierField() As ExternalIdentifierType
Private lidField As String
Private objectTypeField As String
Private statusField As String
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Order:=0)> _
Public Property Name() As InternationalStringType
Get
Return Me.nameField
End Get
Set
Me.nameField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Order:=1)> _
Public Property Description() As InternationalStringType
Get
Return Me.descriptionField
End Get
Set
Me.descriptionField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Order:=2)> _
Public Property VersionInfo() As VersionInfoType
Get
Return Me.versionInfoField
End Get
Set
Me.versionInfoField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("Classification", Order:=3)> _
Public Property Classification() As ClassificationType()
Get
Return Me.classificationField
End Get
Set
Me.classificationField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("ExternalIdentifier", Order:=4)> _
Public Property ExternalIdentifier() As ExternalIdentifierType()
Get
Return Me.externalIdentifierField
End Get
Set
Me.externalIdentifierField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="anyURI")> _
Public Property lid() As String
Get
Return Me.lidField
End Get
Set
Me.lidField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="anyURI")> _
Public Property objectType() As String
Get
Return Me.objectTypeField
End Get
Set
Me.objectTypeField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(DataType:="anyURI")> _
Public Property status() As String
Get
Return Me.statusField
End Get
Set
Me.statusField = value
End Set
End Property
End Class
I hope that I shared all code which is needed to solve my problem.
Upvotes: 0
Views: 189
Reputation: 34429
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
string xml = File.ReadAllText(FILENAME);
StringReader sReader = new StringReader(xml);
XmlReader xReader = XmlReader.Create(sReader);
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
Envelope envelope = (Envelope)serializer.Deserialize(xReader);
}
}
[XmlRoot(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
}
public class Body
{
[XmlElement(Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0")]
public AdhocQueryResponse AdhocQueryResponse { get; set; }
}
public class AdhocQueryResponse
{
[XmlArray(ElementName = "RegistryObjectList", Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]
[XmlArrayItem(ElementName = "ExtrinsicObject", Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]
public ExtrinsicObject[] ExtrinsicObject { get; set; }
}
public class ExtrinsicObject
{
[XmlElement(Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]
public Slot[] Slot { get; set; }
}
public class Slot
{
[XmlAttribute()]
public string name { get; set; }
[XmlArray(ElementName = "ValueList", Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]
[XmlArrayItem(ElementName = "Value", Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]
public string[] Value { get; set; }
}
}
Upvotes: 1