0

I am just trying to pass a hard-coded JSON string to a WCF AJax Enabled Web Service method via GET where I want to accept it and write it to a database. I had to comment out the success function of the $.ajax in order to not et errors with Telerik's WebGrid for now. How can I just get this to the web service:

var input = '{"SbiId":"ca222cf7-be5e-431a-ab93-9a31e8ae2f4a"}';
        $(document).ready(function() {
            // var input ='{"SbiId":"<%=guid %>"}';
            console.log(input);
            $.ajax({
                url: "http://www.blah.com/services/testsService.svc/GetContactsDataAndCountbyGUID",
                type: "GET",
                contentType: "application/json; charset=utf-8",
                data: input,
                dataType: "json",
               <%-- success: function(data) {
                    var mtv = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                    console.log(data);
                    mtv.set_dataSource(data.d.Data);
                    mtv.dataBind();--%>
                //}
            });

EDIT: The service parameter is:

[OperationContract]
        [WebGet]
        public ResultData GetContactsDataAndCountbyGUID(string requestGUID)
        {

The config is:

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior">
          <enableWebScript />
          <webHttp />
        </behavior>
        <behavior name="AlphaFrontEndSiteASP.Services.TestsService">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MetadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="AlphaFrontEndSiteASP.Services.TestsService" behaviorConfiguration="MetadataBehavior">
        <endpoint address="" behaviorConfiguration="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="AlphaFrontEndSiteASP.Services.TestsService" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
user2471435
  • 1,644
  • 7
  • 35
  • 62
  • Can you post your service parameters? – Talspaugh27 Mar 18 '14 at 18:11
  • What error are you getting? One suggestion, when sending data use "POST" instead of "GET". Also check this other link, it might help: http://stackoverflow.com/questions/15530412/make-a-wcf-service-accept-json-data-from-jquery-ajax – Jportelas Mar 18 '14 at 18:12
  • I have to do GET for the method to work with the RadGrid – user2471435 Mar 18 '14 at 18:12
  • var input = '{"SbiId":"ca222cf7-be5e-431a-ab93-9a31e8ae2f4a"}'; should be var input = '{"requestGUID":"ca222cf7-be5e-431a-ab93-9a31e8ae2f4a"}'; – Talspaugh27 Mar 18 '14 at 18:16
  • That does same thing. No requestGUID in the service method – user2471435 Mar 18 '14 at 18:20
  • The method doesn't even get invoked unless I do a GET with Fiddler but it still has no requestGUID. – user2471435 Mar 18 '14 at 18:23
  • Please check if you are missing anything in your service configuration: http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-sec – Jportelas Mar 18 '14 at 18:37
  • I don't think so. I am not doing a REST service with the UriTemplate but an AJAX enabled service. I'll edit to post my config. – user2471435 Mar 18 '14 at 18:46

0 Answers0