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 6159807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:11:37+00:00 2026-05-23T21:11:37+00:00

I’m writing a middle-tier WCF service that needs to fetch some data from a

  • 0

I’m writing a middle-tier WCF service that needs to fetch some data from a back-end .asmx service then serve it up to the front-end as a JSON-encoded string.

I do this by adding a reference to the back-end service to my project, fetching data using that reference, then using a DataContractJsonSerializer to re-serialize the data, like this:

            using (BackendService.BackendServicesSoapClient c = new BackendService.BackendServicesSoapClient())
            {
                // Get data from back-end
                BackendService.SomeData data = c.GetData();

                using (MemoryStream msData = new MemoryStream())
                {
                        // Serialise data to a JSON-encoded string
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BackendService.SomeData));
                        serializer.WriteObject(msData, data);
                        jsonEncodedData = System.Text.Encoding.UTF8.GetString(msData.GetBuffer(), 0, Convert.ToInt16(msData.Length));
                }
            }

Now, on the whole this works. However, the field names in the JSON-encoded string don’t match those in the oringal SomeData class – they all have “Field” appended.

e.g.

contents of BackendService.Somedata:
    Name  : Joe
    Age   : 33

contents of JSON-encoded string
    nameField : Joe
    ageField : 33

It seems to be something to do with the proxy code that’s auto-generated when I add the service reference to my project. If I look in the generated reference.cs I see definitions like this for the data class:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.com/Data/BackEnd/2010/11/")]
public partial class SomeData : object, System.ComponentModel.INotifyPropertyChanged {

    private string nameField;

    private string locationNameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
            this.RaisePropertyChanged("Name");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string Age {
        get {
            return this.ageField;
        }
        set {
            this.ageField = value;
            this.RaisePropertyChanged("Age");
        }
    }
}

as compared to the class defined in the back-end service source as:

public class SomeData
{
    public string Name { get; set; }
    public string Age { get; set; }
}

Is there any way that I can have the field names on the front-end and back-end match?

  • 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-23T21:11:37+00:00Added an answer on May 23, 2026 at 9:11 pm

    The problem is that you are using the XML Serializer when generating the proxy and then trying to re-serialize with the DataContract(Json)Serializer. These use different attributes. Your class is not annotated with the DataContract attribute but rather with the Serializable attribute

    For this to work you either need the DataContract attribute on the proxy class or you need to remove the Serializable attribute. Unfortunately off the top of my head I’m not sure how you can get the generated code to do either of these for you as you are using the XmlSerialier (because the downstream service is an .ASMX service).

    For your own sanity its probably a good idea to create your own class that you control to create the JSON you require, map the data from the ASMX service into this class and then serialize to JSON using your class. This has the added benefit that if the asmx service changed for some reason it wouldn;t affect the JSON unless you wanted it to

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from

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.