Authenticated WCF service that returns JSONP

Posted: November 11, 2011 in .NET
Tags: , ,

Today I was challenged with creating an authenticated, cross-domain, WCF service that returns JSONP.

 Using the ‘out of the box’ WCF configurations this is not possible.  If you attempt to use authentication with an endpoint that allows cross-site scripting, you will recieve an error message like this –

Cross domain javascript callback is not supported in authenticated services

To get around this restriction (It’s not a bug) we can use a custom encoder factory/binding/etc…

In my application, I am using the sample JSONP library that was provided by Miscrosoft.

Then added the appropriate authentication requirement in the web config.

<binding name=”jsonpBinding”>
<httpTransport manualAddressing=”true” authenticationScheme=”Negotiate” />


If anyone needs help with this, First try to implement the JSONP library from Microsoft and let me know if you get stuck. I’ll try to help you configure your app.

  1. Cory says:

    I would be very interested in seeing the code/markup for this. I’m fairly green when it comes to WCF, and this would really help me fix my current issue

    Thanks much,

  2. Ringo says:


    Can you send me also your solution/code about the authentication of the WCF webservice with JSONP.
    I would be very glad.


  3. Cesar Leyva says:

    Really nice, it worked like charm!! 🙂

  4. Ali says:

    Hi Jeremy,
    Can you send me the code for the solution please? I am having problem to get jsonp data form a WCF service with basic authentication. I have spent long time searching for a solution.

  5. Ali says:

    Iam having trouble implementing Restful WCF api with Basic authentication that can be called using AJAX. Can you send me the code please Jeremy? I would be very thankful. I am waiting you email.


  6. Guru says:


    I tried to use this custom binding with Basic authentication but it doesn’t seems to work. I am getting Access is Denied error.

    Service side change

    httpTransport manualAddressing=”true” authenticationScheme=”Basic”

    When I call from the client, I am using xmlhttprequest and I set the Authorization request header using Base64encoded username and password but still I am getting this error.

    Let me know if am doing something wrong.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s