WCF XML序列化消息格式
我希望收到以下格式的输入消息:WCF XML序列化消息格式,xml,wcf,serialization,format,message,Xml,Wcf,Serialization,Format,Message,我希望收到以下格式的输入消息: <abc:message xmlns:abc="http://www.example.com" specver="0730"> <abc:myrequest msgid="0123"> <abc:AttID>3</abc:AttID> <abc:AuthNb>100</abc:AuthNb>
<abc:message xmlns:abc="http://www.example.com" specver="0730">
<abc:myrequest msgid="0123">
<abc:AttID>3</abc:AttID>
<abc:AuthNb>100</abc:AuthNb>
数据合同:
[ServiceContract(Namespace = "http://www.example.com")]
[XmlSerializerFormat]
public interface IService1
{
[OperationContract(Name = "message")]
string RequestData(MyMessageRequest message);
[XmlRoot(Namespace = "http://www.example.com")]
public class MyMessageRequest
{
[XmlAttribute(Namespace = "http://www.example.com", AttributeName = "specver")]
public string Version { get; set; }
[XmlElement(ElementName = "myrequest")]
public MyRequest MyRequest { get; set; }
}
[XmlRoot(Namespace = "http://www.example.com")]
public class MyRequest
{
[XmlAttribute(AttributeName = "msgid")]
public string MsgId { get; set; }
[XmlElement(ElementName = "AttID")]
public string AttributionID { get; set; }
[XmlElement(ElementName = "AuthNb")]
public int AuthenticationNumber { get; set; }
当我将WSDL导入SoapUI时,我得到以下预定义请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eft="http://www.eftpos2000.ch" xmlns:exam="http://www.example.com">
<soapenv:Header/>
<soapenv:Body>
<eft:message>
<!--Optional:-->
<eft:message specver="?">
<!--Optional:-->
<exam:myrequest msgnum="?">
<!--Optional:-->
<exam:AcqID>?</exam:AcqID>
<exam:AmtAuth>?</exam:AmtAuth>
?
?
正如您所注意到的,我有两次使用名为“message”的元素
你知道如何删除XML根元素“message”吗
溴
Nicolas这是因为方法中的变量名为myrequest,第一个myrequest是方法的变量名: 我将其修改为message,下图是SoapUI中所需的请求格式: 这是MyMessageRequest的类: 更新
第一条消息是operationcontract封装的节点。您可以删除它,但它将生成一个具有默认方法名的节点,您不能删除它。这是因为您的方法中的变量名是myrequest,而第一个myrequest是该方法的变量名: 我将其修改为message,下图是SoapUI中所需的请求格式: 这是MyMessageRequest的类: 更新
第一条消息是operationcontract封装的节点。您可以删除它,但它将生成一个具有默认方法名称的节点,您不能删除此节点。以下内容获得一个级别:[xmlement(ElementName=“myrequest”)]以获得两个级别,替换为:[XmlArray(“myrequest”)]和[XmlArrayItem(“myrequest”)]我不需要任何数组。我想去掉一个“myrequest”元素。您是不是打算更改包含两个元素的SOAPUI?数组的XML序列化(public MyRequest[]MyRequest{get;set;})有两个选项1)有一个XML元素并使用XmlElement 2)有两个XML元素并使用XmlArray和XmlArrayItem。现在您的SOAP有两个xml元素,但您说您只想要一个。不能同时支持这两个选项。是的,确切地说:消息中只有一个元素。因此,我想不需要声明数组。下面得到一个级别:[XmlElement(ElementName=“myrequest”)],将两个级别替换为:[XmlArray(“myrequest”)]和[XmlArrayItem(“myrequest”)]我不需要任何数组。我想去掉一个“myrequest”元素。您是不是打算更改包含两个元素的SOAPUI?数组的XML序列化(public MyRequest[]MyRequest{get;set;})有两个选项1)有一个XML元素并使用XmlElement 2)有两个XML元素并使用XmlArray和XmlArrayItem。现在您的SOAP有两个xml元素,但您说您只想要一个。不能同时支持这两个选项。是的,确切地说:消息中只有一个元素。所以我想不需要声明数组。谢谢!我验证了您的方法,但是我也希望删除第一个根元素“message”。我正在编辑我的初始帖子。谢谢!我验证了您的方法,但是我也希望删除第一个根元素“message”。我正在编辑我的第一篇文章。
[XmlRoot(Namespace = "http://www.example.com")]
public class MyMessageRequest
{
[XmlAttribute(Namespace = "http://www.example.com",AttributeName = "specver")]
public string Version { get; set; }
[XmlElement(ElementName = "myrequest")]
public MyRequest MyRequest { get; set; }
}