我目前正在尝试格式化 XML 响应以匹配特定格式,并且在显示我希望隐藏的标签时遇到问题。
所以我目前的回应如下:
<ExportShipmentsResult>
<dataExtract>
<DataExtract>
<shipment>
<ShipID>123456</ShipID>
<ShipNo>PSS111198</ShipNo>
<ShipDate>5 Dec 2011 14:44</ShipDate>
<CustCode>1111/1</CustCode>
<ShipSumm>SU</ShipSumm>
<PONumbers>por:0121</PONumbers>
<ShipComments />
<SuperUsers />
<OrderItem>
<orderItem>
<Code>100001</Code>
<Qty>1</Qty>
</orderItem>
<orderItem>
<Code>100002</Code>
<Qty>1</Qty>
</orderItem>
</OrderItem>
</shipment>
</DataExtract>
</dataExtract>
</ExportShipmentsResult>
</ExportShipmentsResponse>
我的问题是我不希望显示“包装”标签,因此以 OrderItem 为例,我想要的结果是:
<SuperUsers />
<OrderItem>
<Code>100001</Code>
<Qty>1</Qty>
</OrderItem>
<OrderItem>
<Code>100002</Code>
<Qty>1</Qty>
</OrderItem>
</shipment>
我将 OrderItem 设置为列表,并且我正在使用 MessageContract(IsWrapped=false) 但它似乎没有工作,没有错误它只是被忽略。
模型:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.magishop.com/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.magishop.com/", IsNullable = false)]
[MessageContract]
public partial class ExportShipmentsResponse
{
private string resultField;
[MessageBodyMember]/// <remarks/>
public List<dataExtract> ExportShipmentsResult { get; set; }
}
public class dataExtract
{
[MessageBodyMember]
public List<shipment> DataExtract { get; set; }
}
public class shipment
{
[MessageBodyMember]
public string ShipID { get; set; }
[MessageBodyMember]
public string ShipNo { get; set; }
[MessageBodyMember]
public string ShipDate { get; set; }
[MessageBodyMember]
public string CustCode { get; set; }
[MessageBodyMember]
public string ShipSumm { get; set; }
[MessageBodyMember]
public string PONumbers { get; set; }
[MessageBodyMember]
public string ShipComments { get; set; }
[MessageBodyMember]
public string SuperUsers { get; set; }
[MessageBodyMember]
public List<orderItem> OrderItem { get; set; }
}
[MessageContract(IsWrapped=false)]
public class orderItem
{
[MessageBodyMember]
public string Code { get; set; }
[MessageBodyMember]
public string Qty { get; set; }
}
下面是我构建 orderItems 列表并将其添加到我的货件中的位置。
public class CallbackService : ICallbackService
{
public Task<ExportShipmentsResponse> ExportShipments(ExportShipments request)
{
orderItem orderitem1 = new orderItem()
{
Code = "100001",
Qty = "1"
};
orderItem orderitem2 = new orderItem()
{
Code = "100002",
Qty = "1"
};
List<orderItem> orderItems = new List<orderItem>();
orderItems.Add(orderitem1);
orderItems.Add(orderitem2);
shipment shipment = new shipment()
{
ShipID = "123456",
ShipNo = "PSS111198",
ShipDate = "5 Dec 2011 14:44",
CustCode = "1111/1",
ShipSumm = "SU",
PONumbers = "por:0121",
ShipComments = "",
SuperUsers = "",
OrderItem = orderItems
};
List<shipment> shipments = new List<shipment>();
shipments.Add(shipment);
dataExtract dataExtract = new dataExtract()
{
DataExtract = shipments
};
List<dataExtract> dataExtracts = new List<dataExtract>();
dataExtracts.Add(dataExtract);
return Task.FromResult(new ExportShipmentsResponse
{
ExportShipmentsResult = dataExtracts
});
}
}
任何关于我可能遗漏的想法将不胜感激。