Update: Be sure you read Tim Ewald's post about Doc/Literal/Bare - as I explain elsewhere, this post tells only half the story, and in fact mostly misses the point.
My, my, it has been quiet around here for the last week, hasn't it? My excuse is that I was in New Hampshire all week, working heads down on the MSDN rewrite with Tim Ewald and some other friends. My other excuse (always have a backup ready) is that I'm working on some big changes to this blog...but more about that soon enough.
Tim is always a font of entertaining but useless jokes, and enlightening and useful XML knowledge. One thing he pointed out to me this week was SoapDocumentMethodAttribute, in particular when specified with SoapParameterStyle.Bare.
Allow me to explain. Compare the XML produced by the following two functionally equivalent SOAP endpoints:
[WebMethod]
public int Add(int x, int y) { return x + y; }
and
[WebMethod]
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
public int Add(int x, int y) { return x + y; }
Here are the request/response messages for the first variation:
POST /play/bare.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Add"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
int
int
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
int
and here they are for the second variation:
POST /play/bare.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "
http://tempuri.org/Add"
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
http://tempuri.org/">int>
http://tempuri.org/">int>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
http://tempuri.org/">int>
Notice the big difference? With the second variation, the wrapper element that corresponds to the method name has been removed. Which is nice, because it's superfluous - the method is already specified by the SOAPAction header. This is particularly nice in the response message where that extra level of indirection looks a little silly.
To me, this just seems like nicer XML; more like how I would do it if I were just using XmlWriter and raw sockets.