• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5135
  • Last Modified:

Really simple WCF Service using JQuery keep getting error 415 unsupported media type

I wrote a very simple WCF service with one operation contract that returns a list of points. I then wanted to use JQuery to consume the service and get the list of points on to a web page.  I was following Rick Strahl's blog: http://www.west-wind.com/weblog/posts/324917.aspx.

I keep geeting the error: 415 unsupported media type

Please could you let me know where I'm going wrong. Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace Contracts
    [ServiceContract(Name = "TestService", Namespace = "Contracts")]
    public interface ITestService
            Method = "POST", 
            BodyStyle = WebMessageBodyStyle.Wrapped, 
            ResponseFormat = WebMessageFormat.Json)]
        List<Point> Search();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace Contracts
    public class Point
        public double X { get; set; }
        public double Y { get; set; }
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="http://www.json.org/json2.js"></script>
        function Run() {
            var url = "http://localhost:1436/services/testservice.svc/Search";
            var json = JSON.stringify("");
                url: url,
                data: json,
                type: "POST",
                processData: false,
                contentType: "application/json",
                timeout: 10000,
                dataType: "text",
                success: function(result) { alert("Success"); },
                error: function(result) { alert("Error"); }

Open in new window

1 Solution
dnoxsAuthor Commented:
Figured it out. I had the incorrect web config it should have looked as follows:
				<behavior name="WebBehavior">
					<webHttp />
				<behavior name="Portal.Services.TestServiceBehavior">
					<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
					<serviceDebug includeExceptionDetailInFaults="false" />
			<service behaviorConfiguration="Portal.Services.TestServiceBehavior"
				<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="Contracts.ITestService">
						<dns value="localhost" />
				<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now