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

  • Home
  • SEARCH
  • 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 809597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:45:09+00:00 2026-05-15T00:45:09+00:00

I have a wcf restful service with a operation contract that contains two values

  • 0

I have a wcf restful service with a operation contract that contains two values – an int and a string. This is a post call as well.

If i wrap the call using the BodyStyle = WebMessageBodyStyle.Wrapped. What should i assume the xml request will now look like?

  • 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-05-15T00:45:10+00:00Added an answer on May 15, 2026 at 12:45 am

    I ran into the same problem and I believe there are a couple of ways that you can consider doing this. If there are more I’d love to hear them from others.

    First, I’ll tell you how I accomplished this. Step one is to build a utility library that contains a class definition for your data object structure, with appropriate get methods and constructor to initilize the object. Also, you must make the class serializable i.e.

    [Serializable]
    public class myDataObject
    {
        private int _n1;
        private string _s1;
    
        public myDataObject(int n, string s)
        {
            this._n1 = n;
            this._s1 = s;
        }
    
        public int getN1()
        {
            return this._n1;
        }
        public string getS1()
        {
            return this._s1;
        }
    }
    

    }

    It is important to put this in a library so you can reference it from both the client and server side.

    Once you’ve done that, change your WCF service method to look similar to the following:

    [WebInvoke(Method = "POST", UriTemplate = "yourDesignedURI")]
    [OperationContract]
    public bool doSomething(myDataObject o)
    { 
        //implement your service logic, accessing the parameters from o
        int i = o.getN1();
        string s = o.getS1();
        //...etc
        return true;
    }
    

    Once this is complete, publish your service, and then use the help page from your service to view the XML syntax that is required. You can then build your XML using Linq to XML and thereby send your data object over the web as a request. This eliminates the need to wrap and exposes your request xml syntax:

    <myDataObject xmlns="http://schemas.datacontract.org/2004/07/DemoXMLSerialization">
        <_n1>2147483647</_n1>
        <_s1>String content</_s1>
    </myDataObject>
    

    Reference the utility library in your client and create a method in your data later to call the service method, creating the element in your method.

    public void callService(int n1, string s1)
        {
            myDataObject o = new myDataObject(n1, s1);
            string serviceURL = "yourBaseURL";
            string serviceURI = "yourDesignedURI";
    
            using (HttpClient client = new HttpClient(serviceURL))
            {
                client.DefaultHeaders.Add("Content-Type", "application/xml; charset=utf-8");
    
                XNamespace xns = "http://schemas.datacontract.org/2004/07/DemoXMLSerialization";
                XDocument xdoc = new XDocument(
                                    new XElement(xns + "myDataObject",
                                    new XElement(xns + "_n1", o.getN1())
                                    , new XElement(xns + "_s1", o.getS1())));
                using (HttpResponseMessage res = client.Post(serviceURI, HttpContent.Create(xdoc.ToString(SaveOptions.DisableFormatting))))
                {
                    res.EnsureStatusIsSuccessful();
                    //do anything else you want to get the response value
                }
            }
        }
    

    The other thing you can do is redesign your uri to be something like this:
    yourdesignedURI/{myInt}/{myString}

    and then use JSON Serialization to send the object. If you add the line

    BodyStyle=WebMessageBodyStyle.Bare
    

    To your WebInvoke attribute, the help page will expose the full URI for easy viewing.

    I am sure there is probably a way to do it with JQuery as well. Would love to see other solutions to this!

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RESTful service that I am developing in WCF . I am
I have wirtten a RESTful WCF Service. Incorporating E-Tags, expires headers. The caching works
I have a WCF service that I have to reference from a .net 2.0
I have a WCF service, hosted in IIS 7.0 that needs to run database
I have a wcf application hosted in a windows service running a local windows
I have a WCF Web Service which is referenced from a class library. After
I have a WCF service hosted for internal clients - we have control of
I have some WCF methods that are used to transmit information from a server
I have a WCF service and I want to expose it as both a
I have a WCF service running on the IIS with a ServiceHostFactory. It's running

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.