在代码中创建SOAP信封的最佳实践



我有一个很大的SOAP信封体。

在我的应用程序表单之旅中,它的值累积在由用户输入填充的3个不同模型中。

我使用的是MEAN堆栈(MongoExpressNodejs(。。打字稿是语言

构建此XML的最佳方法是什么 ,它将作为SOAP请求的主体传递

  • 如果这是用程序制作的,请建议使用库
  • 我应该使用字符串的concat来完成这个操作吗
  • 还有别的办法吗?比如在某个模板文件中存储原始格式
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:b2b="http://www.abcd.com/B2BService" xmlns:pol="http://schemas.datacontract.org/2004/07/Policy" xmlns:ser="http://schemas.datacontract.org/2004/07/ServiceObjects">
<soapenv:Header/>
<soapenv:Body>
<b2b:IssuePolicy>
<b2b:PolicyIssuanceRequest>
<pol:PaymentDetails>
<ser:ApplicationDetails>
<ser:PartnerApplicationDetails>
<ser:Amount>30887</ser:Amount>
<ser:ApplicationNumber>B11944</ser:ApplicationNumber>
<ser:BusinessType>1</ser:BusinessType>
<ser:ProductCode>11006</ser:ProductCode>
<ser:ProposalNumber>117944P</ser:ProposalNumber>
</ser:PartnerApplicationDetails>                  
</ser:ApplicationDetails>
<ser:BankCode>4502</ser:BankCode>
<ser:BankRefNo>20227141272095</ser:BankRefNo>
<ser:CardHolderName>Amit</ser:CardHolderName>
<ser:ChildID>123</ser:ChildID>
<ser:CrossSellCommonCode>No</ser:CrossSellCommonCode>
<ser:CustomerEmail>amit@gmail.com</ser:CustomerEmail>
<ser:CustomerName>Amit</ser:CustomerName>
<ser:DateofReceipt>2020-08-14</ser:DateofReceipt>
<ser:EduCess>0</ser:EduCess>
<ser:GrossTxnAmount>30887</ser:GrossTxnAmount>
<ser:HigherEduCess>0</ser:HigherEduCess>
<ser:InsuredName>Sunil Kumar</ser:InsuredName>
<ser:NetAmountPaid>30887</ser:NetAmountPaid>
<ser:PGType>Paytm</ser:PGType>
<ser:ParentID>PG21967</ser:ParentID>
<ser:PaymentNumber>1234</ser:PaymentNumber>
<ser:PaymentType>EMI</ser:PaymentType>
<ser:ServiceTax>0</ser:ServiceTax>
</pol:PaymentDetails>
</b2b:PolicyIssuanceRequest>
</b2b:IssuePolicy>
</soapenv:Body>
</soapenv:Envelope>

以下是用于序列化的Net代码:

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 INPUT_FILENAME = @"c:temptest.xml";
const string OUTPUT_FILENAME = @"c:temptest1.xml";
static void Main(string[] args)
{
string soap = File.ReadAllText(INPUT_FILENAME);
StringReader sReader = new StringReader(soap);
XmlReader xReader = XmlReader.Create(sReader);
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
Envelope envelope = (Envelope)serializer.Deserialize(xReader);
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
namespaces.Add("b2b", "http://www.abcd.com/B2BService");
namespaces.Add("ser", "http://schemas.datacontract.org/2004/07/ServiceObjects");
namespaces.Add("pol", "http://schemas.datacontract.org/2004/07/Policy");
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create(OUTPUT_FILENAME, settings);
serializer.Serialize(writer, envelope, namespaces);
}
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Header", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Header Header { get; set; }
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
}
public class Header
{
}
public class Body
{
[XmlArray(ElementName = "IssuePolicy", Namespace = "http://www.abcd.com/B2BService")]
[XmlArrayItem(ElementName = "PolicyIssuanceRequest", Namespace = "http://www.abcd.com/B2BService")]
public List<Policy> Policy { get; set; }
}
public class Policy
{
[XmlElement(ElementName = "PaymentDetails", Namespace = "http://schemas.datacontract.org/2004/07/Policy")]
public Payment Payment { get; set; }
}
public class Payment
{
[XmlArray(ElementName = "ApplicationDetails", Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
[XmlArrayItem(ElementName = "PartnerApplicationDetails", Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public List<Application> Application { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int BankCode { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public long BankRefNo { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string CardHolderName { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int ChildID { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string CrossSellCommonCode { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string CustomerEmail { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string CustomerName { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public DateTime DateofReceipt { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int EduCess { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int GrossTxnAmount { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int HigherEduCess { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string InsuredName { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int NetAmountPaid { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string PGType { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string ParentID { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int PaymentNumber { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public string PaymentType { get; set; }
[XmlElement(Namespace = "http://schemas.datacontract.org/2004/07/ServiceObjects")]
public int ServiceTax { get; set; }
}
public class Application
{
public int Amount { get; set; }
public string ApplicationNumber { get; set; }
public int BusinessType { get; set; }
public int ProductCode { get; set; }
public string ProposalNumber { get; set; }
}
}

相关内容

  • 没有找到相关文章

最新更新