Welcome to EMC Consulting Blogs Sign in | Join | Help

Simon Evans' Blog

My blog covers the technology areas I focus on here at EMC Consulting, namely Architecture using the .NET Framework, ASP.NET, WCF, WCF Data Services and Windows Azure Follow me on twitter @simonevans

Consuming JSON enabled WCF 3.5 services using ASP.net AJAX

There are several blog posts out there that cover the subject of how to consume JSON enabled services from Javascript using ASP.net AJAX. Having scouted around the usual suspects, I think the best article is by Fritz Onion here:

http://www.pluralsight.com/blogs/fritz/archive/2008/01/31/50121.aspx

That said, I haven't found it all plain sailing, so I thought I'd write a blog entry covering the issues I have had to overcome in order to get this functionality working.

Service contract namespace issues

You will see from the article above that setting the namespace in the service contract attribute affects the Javascript namespace ASP.net's auto generated Javascript proxy uses to call the service. So, for example, when you use the namespace http://schemas.conchango.com/myservice/, you would instantiate a client proxy in Javascript using the following code:

var proxy = new schemas.conchango.com.myservice.IMyServiceContract;

where IMyServiceContract is the name of the service contract you are instantiating. Notice that the forward slashed are turned into dot notation by the Javascript proxy generation (and the final forward slash does matter!).

Now this all makes a lot of sense so far, until I introduced schema versioning into my namespace:

http://schemas.conchango.com/2008/03/myservice/

Versioning a schema in this way is standard practice for self describing SOAP services that expose a WSDL. It is important to ensure that you can version your service contract safely, ensuring that you don't break any consuming clients when you update your service to include new and changed functionality. It is also fundamental to publish-subscribe middleware, such as BizTalk understands who subscribes to the published message.

Here a hardnosed RESTafarian may well point out that my WCF endpoint exposed using a WebHttpBinding is indeed not a SOAP service, so this is not important. And they are right, so long as I never want to expose my WCF service through an additional SOAP based endpoint (using a binding such as BasicHttpBinding). This is one on the single most important principles of WCF and Service Orientation: to be able to expose a single service, hosted as a single instance through different endpoints so that you can communicate using different transports, encodings and security. In other words, services should be policy driven.

So I did work around the problem; when I need to version my schema I would use a new namespace such as:

http://schemas.conchango.com/myservice2/

I think this is acceptable, although not standard schema naming practice. At least I can now version my schemas properly and expose my service through SOAP and REST at the same time.

Debugging issues with IIS

In order to use ASP.net debugging with ASP.net websites and services hosted in IIS, Visual Studio requires Integrated Windows Authentication to be enabled. However, if you are developing a web site for anonymous access, you will need to enable anonymous access in IIS too. The problem here is that WCF only allows one authentication scheme to be used. If you attempt to debug a service in IIS under these conditions, you will see the following error message:

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

The simplest workaround to this problem is to switch from using IIS to Visual Studio's development web server. Otherwise I found that I was limited to running the site in IIS.

Published 06 March 2008 06:03 by simon.evans
Filed under: , , , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Allan McLemore said:

I prefer runnning IIS in my DEV environment, so my DEV environment mirrors production as much as possible.  I'm not sure why the VS.NET IDE does not let you initiate debugging when windows authentication is turned off; however, there is an easy workaround for this issue.

1.  Don't initiate start your debugging session directly from VS.NET using "Continue" or "F5".  

2.  Instead set a browser shortcut/bookmark to your application's Url start page.  

3.  From the Debug menu in VS.NET, select "Attach To Process" and then select "aspnet_wp.exe".  And Voila! Debugging works just fine.  

September 24, 2008 15:54
 

Andras Zoltan said:

Regarding the authentication issue, another workaround that allows you to carry on working in IIS is to deploy the services to a child folder.

Have both anonymous and integrated windows authentication enabled on the website, and then have only anonymous access (or whatever security scheme you want to use) on the child folder.  You can then F5 to start debugging, and VS is still happy.

February 9, 2009 08:36
 

Joshua Smith said:

Thanks Andras Zoltan that's a best solution (compared to changing the server or attaching process each time).

Joshua.

April 4, 2010 20:22

Leave a Comment

(required) 
(optional)
(required) 
Submit

About simon.evans

Simon is a Managing Consultant for Conchango in the UK, part of EMC Consulting Services. He is an expert in .NET development, and more specifically in WCF and ASP.NET, having participated in several Microsoft early adoption programs. Simon believes deeply that a broad understanding of key technology concepts is an essential foundation to being a gifted designer and builder of solutions.
Powered by Community Server (Personal Edition), by Telligent Systems