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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:52:53+00:00 2026-05-27T22:52:53+00:00

I have a service that attempting to serialize a list into JSON (using JSON.NET)

  • 0

I have a service that attempting to serialize a list into JSON (using JSON.NET) and return as a string. That’s all well and good, but my JSON is coming back wrapped and I can’t figure out why.

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">[{"DoNotSolicitID":5,"FirstName":"test","LastName":"mcTest","Address1":"11 Elm St","Address2":null,"City":"testville","State":null,"Zip":null,"Zip4":null,"Email":"test@mcTest.com","Phone":null,"BusinessName":null,"PartnerID":"3","Origination":"RDI"},{"DoNotSolicitID":6,"FirstName":"test","LastName":"mcTest","Address1":"11 Elm St","Address2":null,"City":"testville","State":null,"Zip":null,"Zip4":null,"Email":"test@mcTest.com","Phone":null,"BusinessName":null,"PartnerID":"3","Origination":"RDI"}]</string>

The code making the call is:

return JsonConvert.SerializeObject(Lookup(guid, criteria), Formatting.None);

private IList<DNSContract> Lookup(string guid, SearchCriteria criteria)
    {
        apiAuthentication = new APIKeyAuthentication();
        if (!apiAuthentication.IsValidAPIKey(guid))
            throw new WebFaultException<string>("Invalid Key", HttpStatusCode.Forbidden);

        var searchObj = ToSearchObject(criteria);

        SetContext();

        return Svc.SelectWithCriteria(searchObj).Data;
    }

UPDATE: This is a WCF service and in the browser, and fiddler I get the same XML tags. Also, making the call from jQuery/ajax blows up, presumably because it’s getting the tags as well, not the JSON.

UPDATE 2: the SetContext() call will set the ContentType based on the desired type. In this case I’m simply doing the following for JSON in the base class for the REST services:

 OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
 response.ContentType = "application/json";
 response.StatusCode = HttpStatusCode.OK;

So I’m setting the ContentType in teh rsponse and returning a string as a simple output in the service method. This is the interface I’m implementing:

[OperationContract]
    [WebGet(UriTemplate = "/{guid}/search/json?fname={firstname}&lname={lastname}&phone={phone}&email={email}&add1={address1}&add2={address2}&city={city}&state={state}&zip5={zip5}")]
    string LookupRecord(string guid, string firstname, string lastname, string phone, string email, string address1, string address2, string city, string state, string zip5);

Perhaps something in the WebGet that I need to explicitly format to be JSON?

  • 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-27T22:52:54+00:00Added an answer on May 27, 2026 at 10:52 pm

    My problem was that I was not setting the context’s OutgoingResponse.Format to JSON. The context code for a valid JSON response in my situation is

    context.ContentType = "application/json";
    context.StatusCode = HttpStatusCode.OK;
    context.Format = WebMessageFormat.Json;
    

    Oddly enough, setting the attributes on the web method didn’t do anything, I had to set the context explicitly. Since I need to handle XML and JSON responses, this seems the best approach I’ve found.

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

Sidebar

Related Questions

I have a JAX-RPC web service that I am attempting to consume using Spring.
I have a WCF service that I am attempting to connect to via a
We have a service that has some settings that are supported only over net.tcp.
I have .Net service that listens on single port over TCP protocol. Clients connect
I have a web service method that takes a network login (string) as a
I have a web service that I can only hit if I'm logged into
I'm attempting to test that my service is calling Anemone.crawl correctly. I have the
I'm attempting to construct a web service that allows for RESTful requests to return
We have a service that runs methods used for data import/export at specified intervals.
I have a service that sometimes calls a batch file. The batch file takes

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.