Morgan
Morgan

Reputation: 181

How to call an ASP.NET web service from client script in an ASP.NET 2.0 web application?

So I have an asp.net 2.0 web application and I created a web service to post some data from a web form to a database. I now want to use jQuery/AJAX to post the data to the server but since the application is 2.0 and not 3.5+ I don't have the System.Web.Script.Services.ScriptService namespace which seems to be needed (I am posting JSON objects)?

Is there a workaround for this (without upgrading the web application to 3.5)?

Thanks in advance.

EDIT I installed http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&displaylang=en and restared VS2010 but can still not use the namespace.

Upvotes: 4

Views: 2196

Answers (3)

Jeff Sternal
Jeff Sternal

Reputation: 48583

Yes, you can do this without 3.5. First, install Microsoft's AJAX Extensions (aka ASP.NET AJAX 1.0).

Next, you need to add an HttpModule to your web.config (or machine.config; your hosting provider may already have this configured):

<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

Upvotes: 4

Zuuum
Zuuum

Reputation: 1485

There is a comprehensive solution for this. (Available under .Net framework 2.0+ and Mono)

PokeIn gives you an enhanced JSON functionality to makes your server side objects available in client side. Simply, it is a Reverse Ajax library which makes it easy to call JavaScript functions from C#/VB.NET and to call C#/VB.NET functions from JavaScript. It has numerous features like event ordering, resource management, exception handling, marshaling, Ajax upload control, mono compatibility, WCF & .NET Remoting integration and scalable server push.

Upvotes: 2

Lorenzo
Lorenzo

Reputation: 29427

Use Ajax. And include in your project the JSON.NET free library for JSON Serialization/Deserialization for the server side code.

For the client side just use JSON in javascript

Upvotes: 1

Related Questions