none
Tried to access Self Hosted WCF service using JQuery RRS feed

  • Question

  • Hi Everyone,

    I am trying to access WCF service hosted in console application using JQuery web application.

    //Code for WCF Service Hosted in Console Application 
    
                    WebServiceHost selfhost = new WebServiceHost(typeof(CallService), new Uri("http://localhost:3268/test/"));
                    ServiceEndpoint ep = selfhost.AddServiceEndpoint(typeof(ICal), new WebHttpBinding(), "");
                    ServiceDebugBehavior stp = selfhost.Description.Behaviors.Find<ServiceDebugBehavior>();
                    stp.HttpHelpPageEnabled = false;
                    selfhost.Open();
                    Console.WriteLine("service is Up and running");
                    Console.ReadLine();

    Code to access WCF in Jquery

        function WCFJSON() {
                Type = "GET";
                Url = "http://localhost:3268/test/add";
                DataType = "json"; ProcessData = false;
                ContentType = "application/json; charset=utf-8";
                CallService();
            }

    Error MSG

    error Screen shot

    please help me to access WCF service in JQuery. 

     
    Monday, June 22, 2015 6:38 AM

Answers

  • hi jay_parekh,
       As per your case, you can try the following code in your corresponding console :

    //Base Address for CallService Uri httpBaseAddress = new Uri(http://localhost:3268/test); //Instantiate ServiceHost selfhost = new ServiceHost(typeof(CallService.CallService), httpBaseAddress); //Add Endpoint to Host selfhost.AddServiceEndpoint(typeof(CallService.ICal),
    new WSHttpBinding(), ""); //Metadata Exchange ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior(); serviceBehavior.HttpGetEnabled = true; selfhost.Description.Behaviors.Add(serviceBehavior); //Open selfhost.Open(); Console.WriteLine("service is Up and running at : {0}”, httpBaseAddress); Console.ReadLine();

    for more information, Click here to refer the sample code about Calling WCF Services using jQuery.
    Tuesday, June 23, 2015 2:27 AM

All replies

  • 404 means not found. It means it can't find the URL or URI you are pointing to in code, which could be due to bad parms being passed on the formulated URI or UR and a whole lot of other things that can lead to the 404

    And how do you know that you can even access a WCF self-host service from a Web application using Jquery? Where did you get this from?

    Monday, June 22, 2015 7:02 PM
  • hi jay_parekh,
       As per your case, you can try the following code in your corresponding console :

    //Base Address for CallService Uri httpBaseAddress = new Uri(http://localhost:3268/test); //Instantiate ServiceHost selfhost = new ServiceHost(typeof(CallService.CallService), httpBaseAddress); //Add Endpoint to Host selfhost.AddServiceEndpoint(typeof(CallService.ICal),
    new WSHttpBinding(), ""); //Metadata Exchange ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior(); serviceBehavior.HttpGetEnabled = true; selfhost.Description.Behaviors.Add(serviceBehavior); //Open selfhost.Open(); Console.WriteLine("service is Up and running at : {0}”, httpBaseAddress); Console.ReadLine();

    for more information, Click here to refer the sample code about Calling WCF Services using jQuery.
    Tuesday, June 23, 2015 2:27 AM