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 4562296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:11:45+00:00 2026-05-21T18:11:45+00:00

Allright, I’m using a WCF service to handle requests from my web app and

  • 0

Allright, I’m using a WCF service to handle requests from my web app and respond with a JSONP format. I tried all the solutions I could find, studied the documentation (http://msdn.microsoft.com/en-us/library/ee834511.aspx#Y200) and the example project.

The problem is the response object (json) does not get wrapped with the callback supplied in the URL.

Request is like:

http://localhost/socialApi/socialApi.svc/api/login?callback=callback&username=AAAAA&password=BBBB

Web.config looks like:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <trace enabled="true"/>
    <compilation debug="true" targetFramework="4.0"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=*************" /></assemblies></compilation>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service name="RestService.socialApi">
        <endpoint address="" binding="webHttpBinding" contract="RestService.IsocialApi" bindingConfiguration="webHttpBindingJsonP" behaviorConfiguration="webHttpBehavior">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- 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="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttpBehavior" >
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>        
        <binding name="webHttpBindingJsonP" crossDomainScriptAccessEnabled="true"/>
      </webHttpBinding>
    </bindings>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
  </system.serviceModel>
  <system.webServer>
   <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
    <add name="AsrAppEntities" connectionString="myconstring**********" />
  </connectionStrings>
</configuration>

And my operationcontract:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.IO;

namespace socialApi
{
    [ServiceContract]
    public interface IsocialApi
    {
        [OperationContract]
        [WebGet(
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/api/login?username={username}&password={password}")]
        JsonpAuthenticationResponse Login(string username, string password);

    }
}

The response is just normal json:

{"Message":"unauthorized","Status":400,"Token":null}

And I want:

callbackfunction({"Message":"unauthorized","Status":400,"Token":null})

I think it has something to do with the Web.config, because when I modify the example and adjust the Web.config so it looks like mine the example doesn’t function anymore. You would say I pinpointed the problem.. but no.

To supply as much as information as possible, here is the working solution from the example:

Web.config:

<?xml version="1.0"?>
<!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="None" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webScriptEndpoint>
        <standardEndpoint name="" crossDomainScriptAccessEnabled="true"/>
      </webScriptEndpoint>
    </standardEndpoints>
  </system.serviceModel>
</configuration>

And the class:

//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//----------------------------------------------------------------

using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace Microsoft.Samples.Jsonp
{
    [DataContract]
    public class Customer
    {      
        [DataMember]
        public string Name;

        [DataMember]
        public string Address;
    }


    [ServiceContract(Namespace="JsonpAjaxService")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CustomerService
    {
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        public Customer GetCustomer()
        {
           return new Customer() { Name="Bob", Address="1 Example Way"};
        }
    }
}

The above example returns a jsonp object. This is the call from the example:

function makeCall() {
            var proxy = new JsonpAjaxService.CustomerService();
            proxy.set_enableJsonp(true);
            proxy.GetCustomer(onSuccess, onFail, null);
        }

proxy.set_enableJsonp(true); is maybe something I am missing in my call? But I can’t add this in my call because I’m not calling the service from the same solution.

So any idea’s about what’s causing the normal JSON response instead of the request JSONP?

  • 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-05-21T18:11:46+00:00Added an answer on May 21, 2026 at 6:11 pm

    The problem was in the factory settings. In the marckup of the svc file I had to change the factory to System.ServiceModel.Activation.WebScriptServiceHostFactory.

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

Sidebar

Related Questions

when using scaffolding on a controller the views render fine and the app even
I'm using JSF 2.0 and EJB 3.1 in the Glassfish v3 app server. And
My app is working allright in oc4j standalone (grids are working as they should)
data migrates but all cyrillic symbols are replaced with ?. Everything allright with latin
Allright, he is the thing. I am using curl.js for my AMD loader, but
Allright, this is like thousandth time when I get kinda useless information from a
Allright, i have a UIScrollView with some drawings inside. the zoom and scroll works
I am trying to read the UDP packages in python, which were sent from
I've noticed that I can not use all unicode characters in my python source
I'd like to add a third-party DLL from Expression Blend 4 to my source

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.