I would like to receive an input message following this format:
<abc:message xmlns:abc="http://www.example.com" specver="0730">
<abc:myrequest msgid="0123">
<abc:AttID>3</abc:AttID>
<abc:AuthNb>100</abc:AuthNb>
I wrote the following code to do so:
Interface :
[ServiceContract(Namespace = "http://www.example.com")]
[XmlSerializerFormat]
public interface IService1
{
[OperationContract(Name = "message")]
string RequestData(MyMessageRequest message);
Data Contracts :
[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; }
When I import my WSDL into SoapUI, I get the following pre-defined request:
<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>
As you will notice, I have two times an element named "message".
Any ideas how to remove the XML root element "message"?
BR Nicolas
This is because the variable name in your method is myrequest , and the first myrequest is the variable name of the method:
I modified it to message ,the following picture is the request format required in SoapUI:
This is the MyMessageRequest class:
[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; }
}
UPDATE
The first message is a node encapsulated by the operationcontract. You can delete it, but it will generate a node with the default method name, you cannot delete this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.