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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:55:03+00:00 2026-06-12T20:55:03+00:00

I want my WCF service to return json. I test it on ASP.NET Development

  • 0

I want my WCF service to return json.

I test it on ASP.NET Development Server and it works from WCF Test Client (method invokation is ok).

But testing from browser fails with error 400 bad request.

web.config:

<configuration>
   <system.web>
      <compilation debug="true" targetFramework="4.0" />
   </system.web>
   <system.serviceModel>
      <services>
         <service name="WebServiceExample" 
                  behaviorConfiguration="MetadataBehaviour">
            <endpoint 
                address="" 
                behaviorConfiguration="AjaxBehaviour" 
                binding="webHttpBinding" 
                contract="WebService.IWebServiceExample">
               <identity>
                  <dns value="localhost" />
               </identity>
             </endpoint>
          </service>
      </services>
      <behaviors>
          <serviceBehaviors>
             <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
             </behavior>
             <behavior name="MetadataBehaviour">
                 <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
             </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
             <behavior name="AjaxBehaviour">
                 <webHttp/>
             </behavior>
          </endpointBehaviors>
       </behaviors>
       <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
   </system.serviceModel>
   <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
   </system.webServer>
</configuration>

Contract:

[ServiceContract]
public interface IWebServiceExample
{        

    [OperationContract]
    [WebGet(UriTemplate = "/check/{key}",
       ResponseFormat = WebMessageFormat.Json)]
    DataElement Check(string key);
}


[DataContract]
public class DataElement
{

    [DataMember]
    public string Key { get; set; }

    [DataMember]
    public DateTime DateSince { get; set; }

    [DataMember]
    public DateTime DateTill { get; set; }       
}

SVC Markup:

<%@ ServiceHost Language="C#" Debug="true" 
    Service="WebService.WebServiceExample" 
    CodeBehind="WebServiceExample.svc.cs" %>

the URI I try is:

http://localhost:16679/WebServiceExample.svc/check/asd
  • 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-12T20:55:04+00:00Added an answer on June 12, 2026 at 8:55 pm

    Uhh. I’ve got it.
    I think it will be useful for others if I tell how I went through it.

    At first there are differences between WCF service applciation and WCF service libraries. I consider it may lead to conflicts if set full address to endpoint in service application, because of it is set by server (IIS or ASP.NET Development).

    Second, my error was in missing namespace in service name attribute. I set name=”WebServiceExample” instead of name=”WebService.WebServiceExample”.

    I am newbie in WCF and it is not obviously for me that name attribute means service full class name. And error texts doesn’t indicate to it.

    I came to it after reading this topic
    WCF REST Service returns HTTP 400 Bad Request

    The way to come around is to define routings in Global.asax (perverted way, but it works).

    Third, I thought that it is wrong that my service allowed me to view wsdl page. It is strange that RESTful WCF Service generates wsdl, and it was looking like mistake. But know I can tell that it is normal behaviour.

    If in config set up something like this

    then your RESTful service will allow to show

    WSDL on localhost/Service.svc?wsdl

    and

    REST functions on localohost/Service.svc/help

    At last, some usefull links:
    http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-60-sec — WCF service library. I need start VS as admin to run this.

    http://robbincremers.me/2012/01/05/wcf-rest-service-with-xml-json-response-format-according-to-content-type-header/ — WCF service application

    • 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 that return a json. I want to test it
I am able to return an JSON arrray from a WCF rest service. [
I have a wcf service in .net, which i want to return a named
I have a WCF client that download content from the server. the service contract
I want to return CookiesContainer object from WCF service but I cann't return. I
I want to pass HTMLPage as a return value of my WCF REST Service
I want to create WCF service and client. I want to add 2 way
I want to create new WCF service and client. The 2 parties will communicate
I want to create a new WCF service and client. The 2 parties will
I have a WCF Service that I want my client to be able to

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.