在C#WCF数据成员集合上构建SOAP消息时出现问题
我正在创建一个简单的WCF服务来接受下面的SOAP消息在C#WCF数据成员集合上构建SOAP消息时出现问题,c#,wcf,soap,C#,Wcf,Soap,我正在创建一个简单的WCF服务来接受下面的SOAP消息 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jvm="http://siph.com/JVM"> <soapenv:Header/> <soapenv:Body> <jvm:MT_MedicationOrder>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jvm="http://siph.com/JVM">
<soapenv:Header/>
<soapenv:Body>
<jvm:MT_MedicationOrder>
<Patientid>?</Patientid>
<Case_number>?</Case_number>
<DateTime>?</DateTime>
<Order>
<MedicationOrder_id>?</MedicationOrder_id>
<Descr_of_order>?</Descr_of_order>
<!--Optional:-->
<Medication_req_type>?</Medication_req_type>
<!--Zero or more repetitions:-->
<Infusion_ingredient>
<Order_Id>?</Order_Id>
<DrugID>?</DrugID>
<DrugType>?</DrugType>
</Infusion_ingredient>
</Order>
</jvm:MT_MedicationOrder>
</soapenv:Body>
</soapenv:Envelope>
药品订单交易服务合同
[ServiceContract(Namespace = "http://siph.com/JVM")]
public interface IMedicationOrder
{
[OperationContract]
MedicationOrderResponse ProcessOrder(MedicationOrderRequest req);
}
[MessageContract(WrapperName = "MT_MedicationOrder")]
public class MedicationOrderRequest
{
//[MessageHeader]
//public string Dummy;
#region Message Body
[MessageBodyMember(Namespace = "", Name = "Patientid", Order = 1)]
public string PatientId;
[MessageBodyMember(Namespace = "", Name = "Case_number", Order = 2)]
public string CaseNumber;
[MessageBodyMember(Namespace = "", Name = "DateTime", Order = 3)]
public string RequestDateTime;
[MessageBodyMember(Namespace = "", Name = "Order", Order = 4)]
public MedicationOrderTransaction OrderTransaction;
#endregion
}
[DataContract(Namespace = "")]
public class MedicationOrderTransaction
{
[DataMember(Name = "MedicationOrder_id", Order = 1, IsRequired = true)]
public string MedicationOrderID;
[DataMember(Name = "Descr_of_order", Order = 2)]
public string DescriptionOfOrder;
[DataMember(Name = "Medication_req_type", Order = 55)]
public string MedicationReqType;
[DataMember(Name = "Infusion_ingredient", Order = 56)]
public List<InfusionIngredientTransactionList> infusionIngredient;
}
[DataContract]
public class InfusionIngredientTransactionList
{
[DataMember(Name = "Order_Id", Order = 1)]
public string OrderID;
[DataMember(Name = "Drug_Id", Order = 2)]
public string DrugID;
[DataMember(Name = "DrugType", Order = 3)]
public string DrugType;
}
结果:请注意,siph:InfusionCreditionTransactionList的集合是在Infusion\u配料节点内创建的,而不是应该作为集合的Infusion\u配料本身。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jvm="http://siph.com/JVM" xmlns:siph="http://schemas.datacontract.org/2004/07/SIPH.WebService.SAP.Model">
<soapenv:Header/>
<soapenv:Body>
<jvm:MT_MedicationOrder>
<Patientid>?</Patientid>
<Case_number>?</Case_number>
<DateTime>?</DateTime>
<Order>
<MedicationOrder_id>?</MedicationOrder_id>
<Descr_of_order>?</Descr_of_order>
<Medication_req_type>?</Medication_req_type>
<!--Optional:-->
<Infusion_ingredient>
<!--Zero or more repetitions:-->
<siph:InfusionIngredientTransactionList>
<!--Optional:-->
<siph:Order_Id>?</siph:Order_Id>
<!--Optional:-->
<siph:Drug_Id>?</siph:Drug_Id>
<!--Optional:-->
<siph:DrugType>?</siph:DrugType>
</siph:InfusionIngredientTransactionList>
</Infusion_ingredient>
</Order>
</jvm:MT_MedicationOrder>
</soapenv:Body>
</soapenv:Envelope>
?
?
?
?
?
?
?
?
?
请告诉我我做错了什么。谢谢。我还不能“评论”,所以请尝试回答。因此,这个建议可能有点离题,但这是否有助于:
[DataMember(Name = "Infusion_ingredient", Order = 56)]
public List<InfusionIngredientTransactionList> infusionIngredient { get; set; } = new List<InfusionIngredientTransactionList>();
[DataMember(Name=“Infusion\u component”,Order=56)]
公共列表输入元素{get;set;}=new List();
我还同意C#类应该位于List属性之上,因为类的对象被添加到List集合中。如果不是关于主题或没有帮助,我深表歉意。列表的Xml序列化会自动创建两个Xml元素。两个防止两个xml元素需要放入list属性上方的c#类:[XmlElement()]声明一个元素只会创建一个标记。我认为您可以使用消息约定,它允许您指定所需SOAP消息的精确结构。有关message contract的更多信息,请参阅以下链接: