Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:51:26+00:00 2026-06-12T14:51:26+00:00

I am writing a WCF service that should handle a predefined SOAP/XML format that

  • 0

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
{...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:51:27+00:00Added an answer on June 12, 2026 at 2:51 pm

    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.

    public class StackOverflow_12733486
    {
        [ServiceContract(Namespace = "")]
        [XmlSerializerFormat]
        public interface ITest
        {
            [OperationContract]
            SavePetsResponse SavePets(SavePetsRequest request);
        }
        public class Service : ITest
        {
            public SavePetsResponse SavePets(SavePetsRequest request)
            {
                return new SavePetsResponse { Result = true };
            }
        }
        [MessageContract(IsWrapped = false)]
        public class SavePetsRequest
        {
            [MessageBodyMember]
            public Pets Pets { get; set; }
        }
        [MessageContract(WrapperNamespace = "")]
        public class SavePetsResponse
        {
            [MessageBodyMember]
            public bool Result { get; set; }
        }
        public class Pets
        {
            [XmlElement(ElementName = "Dog")]
            public string[] Dogs;
            [XmlElement(ElementName = "Cat")]
            public string[] Cats;
        }
        static Binding GetBinding()
        {
            var result = new BasicHttpBinding();
            return result;
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(ITest), GetBinding(), "");
            host.Open();
            Console.WriteLine("Host opened");
    
            ChannelFactory<ITest> factory = new ChannelFactory<ITest>(GetBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();
            Pets pets = new Pets { Cats = new string[] { "Max" }, Dogs = new string[] { "Fido", "Duke" } };
            proxy.SavePets(new SavePetsRequest { Pets = pets });
    
            ((IClientChannel)proxy).Close();
            factory.Close();
    
            WebClient c = new WebClient();
            c.Headers[HttpRequestHeader.ContentType] = "text/xml";
            c.Headers["SOAPAction"] = "urn:ITest/SavePets";
            string reqBody = @"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
                    <s:Body>
                        <Pets>
                            <Dog>Fido</Dog>
                            <Dog>Duke</Dog>
                            <Cat>Max</Cat>
                        </Pets>
                    </s:Body>
                </s:Envelope>";
            Console.WriteLine(c.UploadString(baseAddress, reqBody));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data model: I am writing a WCF service that needs
I have a WCF service that is responsible for writing a log file. I
I’m writing a WCF service that returns data in JSON format to clients. I
I am writing a WCF client to a SOAP service that returns a mime
I am writing WCF service that uses wsHttpBinding binding, which is not hosted in
I am writing a WCF Service that will require a username and password authentication,
I'm currently writing a WCF web service that uses LINQ to SQL to fetch
I am writing the client side for a WCF service that supports both synchronous
I have a WCF service that can receive several requests/minute (or seconds) that need
I have a windows service that I have been writing in Vb.Net. As part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.