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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:38:07+00:00 2026-05-14T20:38:07+00:00

I have a WCF service which I would like to product XML and JSON

  • 0

I have a WCF service which I would like to product XML and JSON depending on the URI template. So in my service contract I have methods like the following

[ServiceContract]
public interface MultiFormatContract
{
  [OperationContract]
  [WebGet(UriTemplate="/json/data", ResponseFormat = WebMessageFormat.Json)]
  [JSONPBehavior(callback = "callback")]
  public MySerializableObject GetJSONData()


  [OperationContract]
  [WebGet(UriTemplate = "/xml/data", ResponseFormat=WebMessageFormat.Xml)]
  public MySerializableObject GetXMLData()
}

I have a requirement to support JSONP and have used the Microsoft REST sample to support this (following this http://jasonkelly.net/archive/2009/02/24/using-jquery-amp-jsonp-for-cross-domain-ajax-with-wcf-services.aspx). However this has meant that I had to add a custom binding:

  <customBinding>
    <binding name="jsonpBinding">
      <jsonpMessageEncoding/>
      <httpTransport manualAddressing="true"/>
    </binding>
  </customBinding>

This means WCF is no longer using the textMessageEncoding and even though JSONPEncoder overrides the text encoder. My endpoints can no longer produce Xml.

I don’t want to lock consumers to JSON and I’d like to be able to browse to my Xml endpoint to see the Xml for debugging etc.

Any ideas on how I can have both?

  • 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-14T20:38:08+00:00Added an answer on May 14, 2026 at 8:38 pm

    Instead of segregating your response types by creating a ‘virtual’ endpoint using UriTemplate, e.g. “/xml/data”, simply define multiple endpoints with appropriate bindings. You can use a single method and put all of the attributes on one method.

    e.g.

    <endpoint address="json"....
    <endpoint address="jsonp"....
    <endpoint address="xml" ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service which would like to support basicHttpBinding and webHttpBinding. When
I have created a simple wcf service which used the WCF Service Library template.
I have a WCF service which will be hosted under IIS. Now I have
I have a WCF Web Service which is referenced from a class library. After
I have a C# WCF REST Service which allows the addition of a bookmark,
I have a WCF service with the following configuration: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=MetadataEnabled>
I have a WCF service which sits in front of a data collection. I
I have a WCF service which has one end point with configuration of a
I have a service (WCF) with which my ASP.NET page will communicate. The WCF
I have a WCF service hosted in IIS which takes a long time (around

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.