Click here to Skip to main content
15,029,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
Updated 9-Dec-12 22:18pm

1 solution

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
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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900