0

I have seen lot of answers in stackoverflow but they doesnt help me out. I am having a wcf service which when I am running it is showing valid output on the browser.When I am consuming that in a jquery client It is not giving any output.I want to use that wcf service to plot a graph the following is my config file

<system.serviceModel>
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="web">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService1.Service1Behavior">
          <!-- 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>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>

      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

the follwoing is my cs code

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="empdetials")]
        List<employee> empdetials();

    }

the following is my client side code

$(document).ready(function () {
            var sourcee = {};

            $.ajax({
                cache: false,
                async: true,
                type: "GET",
                url: "http://localhost:1331/Service1.svc/empdetials",

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(data.d);
                    sourcee = $.parseJSON(data.d);
                    alert(sourcee);
                },
                error: fnerrorcallback
            });
aravind
  • 978
  • 3
  • 12
  • 21

1 Answers1

0

Just configure your service as crossdomain: http://lucbei.wordpress.com/2010/09/04/cross-domain-wcf-restful-with-jsonp-2/

Boris Gappov
  • 2,483
  • 18
  • 23
  • Hai web developer I am a bit new to wcf . Can you please help me where I have to modify in my web.config file. If I copy and paste the code in that site It is showing an error.. – aravind Nov 04 '13 at 07:44
  • Sry Yar..I don't know silverlight even..please say the modifications in web.config file .Thanks for your fast reply... – aravind Nov 04 '13 at 07:54
  • This example may help you: http://www.codeproject.com/Articles/223572/Calling-Cross-Domain-WCF-service-using-Jquery-Java – Boris Gappov Nov 04 '13 at 07:56
  • Here's one solution: http://stackoverflow.com/questions/10096449/cross-domain-jquery-ajax-request-wcf-rest-service – Boris Gappov Nov 04 '13 at 07:59
  • Try to call your Web service on the server. 1) ajax request to server 2) call wcf from server 3) retur result to client – Boris Gappov Nov 04 '13 at 08:18
  • I got now the solution in the above link..the change is contentType: "text/json; charset=utf-8",dataType: "jsonp", – aravind Nov 04 '13 at 12:10