Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:30:15+00:00 2026-06-04T02:30:15+00:00

I have the WCF REST Service target to .NET Framework 4. I am using

  • 0

I have the WCF REST Service target to .NET Framework 4. I am using Standard End Point of WebScriptEndPoint and using the basic authroization

When I consume this service using the Jquery it is working fine when I have the page with in the same service application i.e. http://localhost. But if I consume this service using a different web application i.e. http://localhost:20984 it is not working.
Fiddler shows when I try http://localhost/WebHttpBindTest/JSONAPIDemo.aspx

GET http://localhost/WebHttpBindTest/Service.svc/GetData?value=some&callback=jsonp1337264181292&_=1337264186941 HTTP/1.1
Accept: text/javascript, application/javascript, */*
Accept-Language: en-us
Referer: http://localhost/WebHttpBindTest/JSONAPIDemo.aspx
Authorization: Basic Y2RtdXNlcjpjZG1wYXNzd29yZA==
x-requested-with: XMLHttpRequest
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Host: localhost
Connection: Keep-Alive
Cookie: __utma=37822774.11348549.1335971819.1337185885.1337195810.36; __utmz=37822774.1335971819.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

But when I try from web app

GET http://localhost/WebHttpBindTest/Service.svc/GetData?value=fdsafa&callback=jsonp1337264499382&_=1337264533468 HTTP/1.1
Accept: application/javascript, */*;q=0.8
Referer: http://localhost:20984/WebSite1/Demo.htm
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: localhost
Connection: Keep-Alive

See the Authorization header is missing when I send using web app page.

Looks like this is cross domain issue. I did enable crossdomainscriptAccess i.e.

Here is the Service Contract:

[ServiceContract]
public interface IService
{
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    string GetData(string value);

}

WEB.Config

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service name="Service" behaviorConfiguration="auth">
        <endpoint address="" kind="webScriptEndpoint" contract="IService" />
      </service>
    </services>
    <standardEndpoints>
      <webScriptEndpoint>
        <standardEndpoint crossDomainScriptAccessEnabled="true">
        </standardEndpoint>
      </webScriptEndpoint>
    </standardEndpoints>
    <behaviors>
      <serviceBehaviors>
        <behavior name="auth">
          <serviceAuthorization serviceAuthorizationManagerType="BasicAuth.BasicAuthorization, BasicAuth" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

JQuery Form:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Base64.js" type="text/javascript"></script>
    <script src="jquery.min.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
        var Type;
        var Url;
        var Data;
        var ContentType;
        var DataType;
        var ProcessData;
        function CallService(successfn,auth) {
            var addHeaders = function (xhr) {
                xhr.setRequestHeader("Authorization", auth);
            };

            $.ajax({
                type: Type, //GET or POST or PUT or DELETE verb
                url: Url, // Location of the service
                data: Data, //Data sent to server
                contentType: ContentType, // content type sent to server
                dataType: DataType, //Expected data format from server
                processdata: ProcessData, //True or False
                beforeSend: addHeaders,
                success: function (msg) {//On Successfull service call
                    successfn(msg);
                },
                error: ServiceFailed// When Service call fails
            });
        }
        function make_base_auth(user, pass) {
            var tok = user + ':' + pass;
            var hash = Base64.encode(tok);
            return "Basic " + hash;
        }
        function getUrl() {
            var auth = make_base_auth('user', 'password');
            Type = "GET";
            Url = "http://localhost/WebHttpBindTest/Service.svc/GetData?value=" + $('#txtCode').val();
            ContentType = "text/json; charset=utf-8";
            DataType = "jsonp";
            ProcessData = true;

            CallService(ServiceSucceeded,auth);
        }


        function ServiceSucceeded(result) {
            var resultObject = null;

            if (DataType == "jsonp") {
                if (Url.indexOf(".asmx/") > 0) {
                    resultObject = result.d; 
                }
                else {
                    $("#div1").html("Result:" + result);
                }
            }
        }
        function ServiceFailed(result) {
            alert('Service call failed: ' + result.status + '' + result.statusText);
            Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null;
        }
    </script>
</head>
<body>
    <div id="container">

        <h1>JSON API Demo</h1>

        <div>
            <p>Type Something: <input type="text" id="txtCode" />
            <button type="submit"value="submit" id="btnGetUrl" onclick="getUrl()">Get</button>
        </div>
        <br /><br />
        <center><div id="div1" style="font-size:larger"></div>  </center>
</div>  
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:30:16+00:00Added an answer on June 4, 2026 at 2:30 am

    If you want to access the endpoint via jQuery, you should use the <webHttpEndpoint> standard endpoint, not the <webScriptEndpoint>. webScriptEndpoints should be used for clients which use the ASP.NET AJAX framework only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to consume a .net WCF rest service using JAX-WS lately. Due
I created a new wcf rest service using .net 4. I have created a
I have an asp.net 4 application that hosts a WCF REST service via WebServiceHost...
I have a REST service consumed by a .Net WCF client. When an error
I have a self hosted WCF Rest service that I am using to simulate
I have trying to design a REST service in .NET 3.5 with WCF REST
I have deployed an asp.net site with a wcf rest service to a virtual
I want to consume a WCF REST service using an AJAX call. Suppose I
I have a WCF rest service using webHttpBinding that returns JSON result. The problem
I have a WCF/REST web service that I'm considering using Linq to SQL to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.