Using raw XML as an operation parameter
WCF service operation calls are transferred as SOAP messages (of XML format) over the transport layer. These kinds of SOAP XML messages are automatically generated via the WCF message/data serialization system. In addition to this, we can also explicitly return custom data of raw XML format.
How to do it...
To return raw XML format data, the simplest way is using a .NET built-in XML data type, such as System.Xml
types or LINQ to XML types. In our sample service, we use the XElement
type of LINQ to XML to return some custom XML data in service operation.
The following code shows the ServiceContract
of the sample service:
[ServiceContract] public interface IService1 { [OperationContract] XElement GetXmlData(); }
In the implementation code of the service operation, we directly construct an XElement
instance and return it to the client (see the Service1
class shown as follows):
public class Service1 : IService1 { public XElement GetXmlData() ...