I am writing a WCF service that should handle a predefined SOAP/XML format that I have no control over.
Here is my exposed service contract:
[OperationContract]
[WebInvoke(Method = "POST")]
bool SavePets(Pets Pets);
The SOAP that this service expects is:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SavePets xmlns="http://tempuri.org">
<Pets>
<Dog>
<Name>Fido</Name>
</Dog>
<Dog>
<Name>Duke</Name>
</Dog>
<Cat>
<Name>Max</Name>
</Cat>
</Pets>
</SavePets>
</s:Body>
</s:Envelope>
However, I need for either the method name (SavePets) or the parameter name (Pets) to be removed, as such, so the service does not expect it:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Pets>
<Dog>
<Name>Fido</Name>
</Dog>
<Dog>
<Name>Duke</Name>
</Dog>
<Cat>
<Name>Max</Name>
</Cat>
</Pets>
</s:Body>
</s:Envelope>
I’m not using DataContracts or MessageContracts. My Pets class looks like this:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = false, Namespace = "http://tempuri.org")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://tempuri.org", IsNullable = true)]
public partial class Pets
{...
}
To remove one of those elements, you can use an unwrapped message contract (a type decorated with
[MessageContract(IsWrapped = false)]). The code below shows one service which could receive that request.