POX (Plain-Old-Xml) service using Stream parameters
I want to develop a WCF service, which will receive various XMLs and save them for fu开发者_运维问答rther processing. I can't stick to particular data type, because the incoming XMLs will be totally different. So far I've chosen the approach using Stream parameters:
[ServiceContract]
public interface IApiService
{
[WebInvoke(Method = "POST",
UriTemplate = "getXml",
BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
Stream getXml(Stream request);
}
I am returning some text for response. The service will be called by external application and I want to stay away from .NET-specific issues.
Is there a better approach to do it?
If the XML which you'll receive is always well-formed, you can use the XElement
or XmlElement
types as the input and return values. The former is an IXmlSerializable
type which WCF can handle, the latter is a type treated as a special case by the WCF serializer. The advantage is that you have all the XML OM to manipulate the data, and the outgoing content-type will be set automatically for you.
If the input/output isn't necessarily well-formed XML, then your solution (with Stream
) is the only one you can use.
If the XML that is passed can be arbitrary, Stream
looks a good solution. You could also use byte[]
or even string
.
精彩评论