Search code examples
c#xmlweb-serviceswcfsoap

How do I suppress the method name from my xml in a WCF Web Service?


I do not want my web method name as part of the hierarchy in my XML. I strictly want the object that was passed in to be encapsulated in a SOAP envelope, then have an empty Header, and in the Body I want the first sub-element to be of the type of object I'm passing in (in this case, ns:QueryRequest).

When I had an .asmx web page, I was getting two extra levels in my hierarchy (i.e., the web method name and the name of the object being passed into the web method). So, beneath Body, I had GetData -> actualData -> ns:QueryRequest. I was able to suppress the first two elements by creating a [SoapDocumentMethod] on the web method and setting ParameterStyle=SoapParameterStyle.Bare.

I'm creating a WCF web page now for a comparison. I specified [XmlSerializerFormat] beneath [OperationContract] on the interface and this resolved my namespace issues. I tried implementing [WebInvoke] and [WebGet] beneath that, with a BodyStyle=WebMessageBodyStyle.Bare, but it isn't suppressing the GetData method name in the interface. I need the first element beneath Body to be ns:QueryRequest and not GetData.

How can I accomplish this?


Solution

  • You define a [MessageContract(IsWrapped=false)] for the input parameter and a separate one for the output. This will suppress the unwanted root element.