XmlElement wrapped in extra tag in SOAP request

Hi I have a service-proxy with one method:

void SendRequest(MyMessage msg);

The MyMessage is defined as follows:

public class MyMessage{
    public XmlElement Body;

    public MyMessage(XmlElement Body){
        this.Body = Body;

Now, the problem is that when I send the request, the Body is wrapped in a tag like so:

               <SomeData>Hello world</SomeData>

when what I really want is:

               <SomeData>Hello world</SomeData>

Can someone please help? I'm starting to become desperate! :/

EDIT: The reason I want to send XmlElement is that the service will accept a various amount of XML-formats, and will do the xsd-validation and transformation on the server-side. This is only supposed to be sort of a wrapper.

There is also no way I can have the endpoint-server simply accept the "wrong" xml-structure, as I'm not in control of that.


Alright, so it seems I had to totally abadon WCF for this to work.

What I did was to create two simple methods:

    XDocument ConstructSoapEnvelope(string messageId, string action, XDocument body)
        XDocument xd = new XDocument();
        XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/";
        XNamespace a = "http://www.w3.org/2005/08/addressing";

        XElement soapEnvelope = new XElement(s + "Envelope", new XAttribute(XNamespace.Xmlns + "s", s), new XAttribute(XNamespace.Xmlns + "a", a));
        XElement header = new XElement(s + "Header");
        XElement xmsgId = new XElement(a + "MessageID", "uuid:" + messageId);
        XElement xaction = new XElement(a + "Action", action);

        XElement soapBody = new XElement(s + "Body", body.Root);
        xd = new XDocument(soapEnvelope);
        return xd;

    string HttpSOAPRequest(XmlDocument doc, string add, string proxy, X509Certificate2Collection certs)
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(add);
        req.ClientCertificates = certs;
        if (proxy != null) req.Proxy = new WebProxy("", true);

        req.Headers.Add("SOAPAction", "\"\"");

        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";
        Stream stm = req.GetRequestStream();
        WebResponse resp = req.GetResponse();
        stm = resp.GetResponseStream();
        StreamReader r = new StreamReader(stm);

       return r.ReadToEnd();

ConstructSoapEnvelope simply creates a soap-envelope with a header and a body (tailored for my needs with ws-addressing)

and the HttpSOAPRequest is a slightly modified version of the one found here: http://www.eggheadcafe.com/articles/20011103.asp

I had to modify it to accept client-certificates, in order for my SSL-communication to work..

Hope this helps someone else as well! :)

Need Your Help

ATL COM Server - cretaing COM object defined in ATL Server from this server

.net c++ visual-studio com atl

I have created an ATL COM Server C++ project using a Visual Studio 2005 wizard. I added a new COM class using the ATL Simple Object wizard. Now when I try to create this COM class instance from my ...

Rails - Drop down list with 'other' that allows creation of new model object

ruby-on-rails model ruby-on-rails-4 collection-select

I currently have a rather complicated _request_form for creating new Requests in my website. Currently, when creating a request, employees must choose their name from a dropdown menu like so: