Создайте два класса, один для успешного и один для неудачного сообщения. В зависимости от Status Code
разобрать ответ на соответствующий класс. Если вы думаете о создании динамических классов, вы можете попробовать использовать ключевое слово dynamic
, но C#
- это язык строгого типа. Кроме того, есть небольшой инструмент, который может помочь вам создать класс из ответа, попробуйте, вот ссылка .
Итак, связь между вашими статусами - это часть заголовка , поэтому я разделил его на один класс.
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace Xml2CSharp
{
public class HeaderDto
{
[XmlRoot(ElementName = "RequestMessageKey", Namespace = "http://www.finacle.com/fixml")]
public class RequestMessageKey
{
[XmlElement(ElementName = "RequestUUID", Namespace = "http://www.finacle.com/fixml")]
public string RequestUUID { get; set; }
[XmlElement(ElementName = "ServiceRequestId", Namespace = "http://www.finacle.com/fixml")]
public string ServiceRequestId { get; set; }
[XmlElement(ElementName = "ServiceRequestVersion", Namespace = "http://www.finacle.com/fixml")]
public string ServiceRequestVersion { get; set; }
[XmlElement(ElementName = "ChannelId", Namespace = "http://www.finacle.com/fixml")]
public string ChannelId { get; set; }
}
[XmlRoot(ElementName = "ResponseMessageInfo", Namespace = "http://www.finacle.com/fixml")]
public class ResponseMessageInfo
{
[XmlElement(ElementName = "BankId", Namespace = "http://www.finacle.com/fixml")]
public string BankId { get; set; }
[XmlElement(ElementName = "TimeZone", Namespace = "http://www.finacle.com/fixml")]
public string TimeZone { get; set; }
[XmlElement(ElementName = "MessageDateTime", Namespace = "http://www.finacle.com/fixml")]
public string MessageDateTime { get; set; }
}
[XmlRoot(ElementName = "UBUSTransaction", Namespace = "http://www.finacle.com/fixml")]
public class UBUSTransaction
{
[XmlElement(ElementName = "Id", Namespace = "http://www.finacle.com/fixml")]
public string Id { get; set; }
[XmlElement(ElementName = "Status", Namespace = "http://www.finacle.com/fixml")]
public string Status { get; set; }
}
[XmlRoot(ElementName = "HostTransaction", Namespace = "http://www.finacle.com/fixml")]
public class HostTransaction
{
[XmlElement(ElementName = "Id", Namespace = "http://www.finacle.com/fixml")]
public string Id { get; set; }
[XmlElement(ElementName = "Status", Namespace = "http://www.finacle.com/fixml")]
public string Status { get; set; }
}
[XmlRoot(ElementName = "HostParentTransaction", Namespace = "http://www.finacle.com/fixml")]
public class HostParentTransaction
{
[XmlElement(ElementName = "Id", Namespace = "http://www.finacle.com/fixml")]
public string Id { get; set; }
[XmlElement(ElementName = "Status", Namespace = "http://www.finacle.com/fixml")]
public string Status { get; set; }
}
[XmlRoot(ElementName = "ResponseHeader", Namespace = "http://www.finacle.com/fixml")]
public class ResponseHeader
{
[XmlElement(ElementName = "RequestMessageKey", Namespace = "http://www.finacle.com/fixml")]
public RequestMessageKey RequestMessageKey { get; set; }
[XmlElement(ElementName = "ResponseMessageInfo", Namespace = "http://www.finacle.com/fixml")]
public ResponseMessageInfo ResponseMessageInfo { get; set; }
[XmlElement(ElementName = "UBUSTransaction", Namespace = "http://www.finacle.com/fixml")]
public UBUSTransaction UBUSTransaction { get; set; }
[XmlElement(ElementName = "HostTransaction", Namespace = "http://www.finacle.com/fixml")]
public HostTransaction HostTransaction { get; set; }
[XmlElement(ElementName = "HostParentTransaction", Namespace = "http://www.finacle.com/fixml")]
public HostParentTransaction HostParentTransaction { get; set; }
[XmlElement(ElementName = "CustomInfo", Namespace = "http://www.finacle.com/fixml")]
public string CustomInfo { get; set; }
}
[XmlRoot(ElementName = "Header", Namespace = "http://www.finacle.com/fixml")]
public class Header
{
[XmlElement(ElementName = "ResponseHeader", Namespace = "http://www.finacle.com/fixml")]
public ResponseHeader ResponseHeader { get; set; }
}
}
}
Класс ответа Success будет выглядеть примерно так ...
/*
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
*/
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using static Xml2CSharp.HeaderDto;
namespace Xml2CSharp
{
public class SuccessDto
{
public RequestMessageKey RequestMessageKey { get; set; }
public ResponseMessageInfo ResponseMessageInfo { get; set; }
public UBUSTransaction UBUSTransaction { get; set; }
public HostTransaction HostTransaction { get; set; }
public HostParentTransaction HostParentTransaction { get; set; }
public ResponseHeader ResponseHeader { get; set; }
public Header Header { get; set; }
[XmlRoot(ElementName = "AcctType", Namespace = "http://www.finacle.com/fixml")]
public class AcctType
{
[XmlElement(ElementName = "SchmCode", Namespace = "http://www.finacle.com/fixml")]
public string SchmCode { get; set; }
[XmlElement(ElementName = "SchmType", Namespace = "http://www.finacle.com/fixml")]
public string SchmType { get; set; }
}
[XmlRoot(ElementName = "PostAddr", Namespace = "http://www.finacle.com/fixml")]
public class PostAddr
{
[XmlElement(ElementName = "Addr1", Namespace = "http://www.finacle.com/fixml")]
public string Addr1 { get; set; }
[XmlElement(ElementName = "Addr2", Namespace = "http://www.finacle.com/fixml")]
public string Addr2 { get; set; }
[XmlElement(ElementName = "Addr3", Namespace = "http://www.finacle.com/fixml")]
public string Addr3 { get; set; }
[XmlElement(ElementName = "City", Namespace = "http://www.finacle.com/fixml")]
public string City { get; set; }
[XmlElement(ElementName = "StateProv", Namespace = "http://www.finacle.com/fixml")]
public string StateProv { get; set; }
[XmlElement(ElementName = "PostalCode", Namespace = "http://www.finacle.com/fixml")]
public string PostalCode { get; set; }
[XmlElement(ElementName = "Country", Namespace = "http://www.finacle.com/fixml")]
public string Country { get; set; }
[XmlElement(ElementName = "AddrType", Namespace = "http://www.finacle.com/fixml")]
public string AddrType { get; set; }
}
[XmlRoot(ElementName = "BankInfo", Namespace = "http://www.finacle.com/fixml")]
public class BankInfo
{
[XmlElement(ElementName = "BankId", Namespace = "http://www.finacle.com/fixml")]
public string BankId { get; set; }
[XmlElement(ElementName = "Name", Namespace = "http://www.finacle.com/fixml")]
public string Name { get; set; }
[XmlElement(ElementName = "BranchId", Namespace = "http://www.finacle.com/fixml")]
public string BranchId { get; set; }
[XmlElement(ElementName = "BranchName", Namespace = "http://www.finacle.com/fixml")]
public string BranchName { get; set; }
[XmlElement(ElementName = "PostAddr", Namespace = "http://www.finacle.com/fixml")]
public PostAddr PostAddr { get; set; }
}
[XmlRoot(ElementName = "AcctId", Namespace = "http://www.finacle.com/fixml")]
public class AcctId
{
[XmlElement(ElementName = "AcctId", Namespace = "http://www.finacle.com/fixml")]
public string AcctId { get; set; }
[XmlElement(ElementName = "AcctType", Namespace = "http://www.finacle.com/fixml")]
public AcctType AcctType { get; set; }
[XmlElement(ElementName = "AcctCurr", Namespace = "http://www.finacle.com/fixml")]
public string AcctCurr { get; set; }
[XmlElement(ElementName = "BankInfo", Namespace = "http://www.finacle.com/fixml")]
public BankInfo BankInfo { get; set; }
}
[XmlRoot(ElementName = "BalAmt", Namespace = "http://www.finacle.com/fixml")]
public class BalAmt
{
[XmlElement(ElementName = "amountValue", Namespace = "http://www.finacle.com/fixml")]
public string AmountValue { get; set; }
[XmlElement(ElementName = "currencyCode", Namespace = "http://www.finacle.com/fixml")]
public string CurrencyCode { get; set; }
}
[XmlRoot(ElementName = "AcctBal", Namespace = "http://www.finacle.com/fixml")]
public class AcctBal
{
[XmlElement(ElementName = "BalType", Namespace = "http://www.finacle.com/fixml")]
public string BalType { get; set; }
[XmlElement(ElementName = "BalAmt", Namespace = "http://www.finacle.com/fixml")]
public BalAmt BalAmt { get; set; }
}
[XmlRoot(ElementName = "BalInqRs", Namespace = "http://www.finacle.com/fixml")]
public class BalInqRs
{
[XmlElement(ElementName = "AcctId", Namespace = "http://www.finacle.com/fixml")]
public AcctId AcctId { get; set; }
[XmlElement(ElementName = "AcctBal", Namespace = "http://www.finacle.com/fixml")]
public List<AcctBal> AcctBal { get; set; }
}
[XmlRoot(ElementName = "BalInqResponse", Namespace = "http://www.finacle.com/fixml")]
public class BalInqResponse
{
[XmlElement(ElementName = "BalInqRs", Namespace = "http://www.finacle.com/fixml")]
public BalInqRs BalInqRs { get; set; }
[XmlElement(ElementName = "BalInq_CustomData", Namespace = "http://www.finacle.com/fixml")]
public string BalInq_CustomData { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://www.finacle.com/fixml")]
public class Body
{
[XmlElement(ElementName = "BalInqResponse", Namespace = "http://www.finacle.com/fixml")]
public BalInqResponse BalInqResponse { get; set; }
}
[XmlRoot(ElementName = "FIXML", Namespace = "http://www.finacle.com/fixml")]
public class FIXML
{
[XmlElement(ElementName = "Header", Namespace = "http://www.finacle.com/fixml")]
public Header Header { get; set; }
[XmlElement(ElementName = "Body", Namespace = "http://www.finacle.com/fixml")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
}
}
}
А класс Failed будет таким
/*
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
*/
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using static Xml2CSharp.HeaderDto;
namespace Xml2CSharp
{
public class FailedDto
{
public RequestMessageKey RequestMessageKey { get; set; }
public ResponseMessageInfo ResponseMessageInfo { get; set; }
public UBUSTransaction UBUSTransaction { get; set; }
public HostTransaction HostTransaction { get; set; }
public HostParentTransaction HostParentTransaction { get; set; }
public ResponseHeader ResponseHeader { get; set; }
public Header Header { get; set; }
[XmlRoot(ElementName = "ErrorDetail", Namespace = "http://www.finacle.com/fixml")]
public class ErrorDetail
{
[XmlElement(ElementName = "ErrorCode", Namespace = "http://www.finacle.com/fixml")]
public string ErrorCode { get; set; }
[XmlElement(ElementName = "ErrorDesc", Namespace = "http://www.finacle.com/fixml")]
public string ErrorDesc { get; set; }
[XmlElement(ElementName = "ErrorSource", Namespace = "http://www.finacle.com/fixml")]
public string ErrorSource { get; set; }
[XmlElement(ElementName = "ErrorType", Namespace = "http://www.finacle.com/fixml")]
public string ErrorType { get; set; }
}
[XmlRoot(ElementName = "FIBusinessException", Namespace = "http://www.finacle.com/fixml")]
public class FIBusinessException
{
[XmlElement(ElementName = "ErrorDetail", Namespace = "http://www.finacle.com/fixml")]
public ErrorDetail ErrorDetail { get; set; }
}
[XmlRoot(ElementName = "Error", Namespace = "http://www.finacle.com/fixml")]
public class Error
{
[XmlElement(ElementName = "FIBusinessException", Namespace = "http://www.finacle.com/fixml")]
public FIBusinessException FIBusinessException { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://www.finacle.com/fixml")]
public class Body
{
[XmlElement(ElementName = "Error", Namespace = "http://www.finacle.com/fixml")]
public Error Error { get; set; }
}
[XmlRoot(ElementName = "FIXML", Namespace = "http://www.finacle.com/fixml")]
public class FIXML
{
[XmlElement(ElementName = "Header", Namespace = "http://www.finacle.com/fixml")]
public Header Header { get; set; }
[XmlElement(ElementName = "Body", Namespace = "http://www.finacle.com/fixml")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
}
}
}
Считайте это псевдокодом, поскольку он не тестировался. Поэтому, когда вы получите ответ, проанализируйте заголовок и прочитайте узел, который вам нужен, чтобы проверить, является ли его сообщение Success или Failed, а затем просто проанализируйте его как этот объект.