Click here to Skip to main content
12,953,491 members (61,296 online)
Rate this:
Please Sign up or sign in to vote.
See more:
//When I run My Form Then Service Failed Function In Jquery Called!..
But I don't know where is the problem??
//Code For Call WCF Service In WebForm
<html xmlns="">
<head runat="server">
    <script type="text/javascript" src=""></script>  
<script type="text/javascript"> 
    var Type;
        var Url;
        var Data;
        var ContentType;
        var DataType;               
        function CallService() {            
                type: Type, //GET or POST or PUT or DELETE verb
                url: Url, // Location of the service
                data: Data, //Data sent to server
                contentType: ContentType, // content type sent to server
                dataType: DataType, //Expected data format from server             
                success: function (msg) {//On Successfull service call
                error: ServiceFailed// When Service call fails
        function ServiceFailed(result) {
            alert('Service call failed: ' + result.status + '' + result.statusText);
            Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null;
        function WCFJSON() {
            var id = "1";
            Type = "GET";
            Url = "http://localhost:52410/RestServiceImpl.svc/JSONData";
           Data = '{"id"= "' + id + '"}';
           // Data = {};
            ContentType = "application/json; charset=utf-8";
            DataType = "json"; 
        function ServiceSucceeded(result) {
            if (DataType == "json") {
                resultObject = result.JSONDataResult;
                for (i = 0; i < resultObject.length; i++) {
         function () {
//Code In Web Config
      <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        <behavior name="web">
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>
//Code In Wcf Service...
//My InterFace IRestServiceImpl In Wcf Service!...
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Wrapped)
        string XMLData(string id);
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped)
        string JSONData(string id);
//This Is InterFace Implementaion
    public class RestServiceImpl : IRestServiceImpl
        public string XMLData(string id)
            return "You requested product " + id;
        public string JSONData(string id)
            return "You requested product " + id;
Posted 9-Dec-12 19:25pm
Updated 9-Dec-12 22:18pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I can see one problem in the code.
That is the starting script tag is missing.
Your whole JavaScript Code should be inside script tags, but there is no start tag of script.

Just above the code var Type;, you should have one script tag like <script>. You have one end tag for this, but no start tag.
Please add this.

RahulRana723 10-Dec-12 2:38am
sir code is successfully problem is why the servicefalied method is calling? error is 0--No Transport
Tadit Dash 10-Dec-12 2:42am
Have you added that script start tag? Sometimes missing tags creates problem.
RahulRana723 10-Dec-12 4:17am
yes my code script tag already added

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100