#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    WCF - getting the error 500 when making an AJAX call from jQuery.


    Hi,

    I'm new to WCF.

    I'm getting the below error when I try to call a WCF service from jQuery.

    500 - System.ServiceModel.ServiceActivationException

    Here is the ajax call from jQuery:-

    Code:
        $.ajax({
            type: "POST",
            url: "Service.svc/ConvertTemperatureSimple",
            data: 2,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function () {
                alert("success");
            },
            error: function (err) {
                alert(err.status + " - " + err.statusText);
            }
        });
    And here is what I have in my web.config file:-

    Code:
      <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="AJAXEnabledWebService.ServiceAspNetAjaxBehavior">
              <enableWebScript />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" />
        <services>
          <service name="AJAXEnabledWebService.IService">
            <endpoint address="" behaviorConfiguration="AJAXEnabledWebService.ServiceAspNetAjaxBehavior"
              binding="webHttpBinding" contract="AJAXEnabledWebService.IService" />
          </service>
        </services>
      </system.serviceModel>

    And here is OperationContart I have IService interface in the Service.svc.cs file:-

    Code:
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
            decimal ConvertTemperatureSimple(decimal t, string unit);
    I'm using WCF 4 & VS 2010. Please let me know if you need additional information.

    I can't get this to work. I'm thinking there must be something incorrect in my web.config file. Any help is appreciated.

    Thanks
    Jai
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    38
    Rep Power
    3
    I suggest debugging into ajax and into the service. On the latter, a unit test debug is preferred. Your problem will likely be answered once you step into everything! In the future, build a repository just for catching errors like this. It is good prac! Good Luck!

IMN logo majestic logo threadwatch logo seochat tools logo