none
Consume RESTful WCF service using jQuery $.ajax RRS feed

  • Question

  • Hi All,

    I am trying to consume RESTful WCF service using jQuery $.ajax function and I am facing issues with it.

    Below is my jQuery code,

    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "http://localhost:55205/Services/UserService.svc/GetUserProjects",
            data: '{"gpn": "' + 1 + '"}',
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            success: function (data, textStatus, jqXHR) {
                alert(textStatus);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(textStatus);
            },
            complete: function (jqXHR, textStatus) {
            }
        });
    });

    Below is my WCF configuration,

      <system.serviceModel>
        <services>
          <service name="BugTracker.WcfService.Services.UserService" behaviorConfiguration="BugTracker.WcfService.Services.UserServiceServiceBehavior">
            <endpoint address="" behaviorConfiguration="BugTracker.WcfService.Services.UserServiceAspNetAjaxBehavior"
              binding="webHttpBinding" contract="BugTracker.WcfService.Services.IUserService" />
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="BugTracker.WcfService.Services.UserServiceAspNetAjaxBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="BugTracker.WcfService.Services.UserServiceServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <webHttpBinding>
            <binding name="" crossDomainScriptAccessEnabled="true"></binding>
          </webHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" />
        <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
      </system.serviceModel>

    Below is my WCF code, 

        [ServiceContract]
        public interface IUserService
        {
            [OperationContract]
            [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetUserProjects/{gpn}")]
            IList<Project> GetUserProjects(String gpn);
        }

    The issue I am facing is, the WCF service implementation is not hit when I try debugging the code. The service is not hit anytime. 

    Can anyone suggest if the code I am writing is the correct code or am I missing anything?

    Please suggest. Thanks in advance

    Sunday, January 12, 2014 9:03 AM

Answers