156 lines
7.3 KiB
XML
156 lines
7.3 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
|
/*
|
|
* Copyright 2002-2008 the original author or authors.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
-->
|
|
<chapter xml:id="ajax" xmlns="http://docbook.org/ns/docbook" version="5">
|
|
<title>ASP.NET AJAX</title>
|
|
|
|
<sect1 xml:id="introduction-ajax">
|
|
<title>Introduction</title>
|
|
|
|
<para>Spring's ASP.NET AJAX integration allows for a plain .NET object
|
|
(PONO), that is one that doesn't have any attributes or special base
|
|
classes, to be exported as a web service, configured via dependency
|
|
injection, 'decorated' by applying AOP, and then exposed to client side
|
|
JavaScript.</para>
|
|
</sect1>
|
|
|
|
<sect1 xml:id="webServices">
|
|
<title>Web Services</title>
|
|
|
|
<para>Spring.NET, and particularly Spring.Web, improved <ulink
|
|
url="http://www.springframework.net/doc-latest/reference/html/webservices.html">support
|
|
for web services</ulink> in .NET with the
|
|
<literal>WebServiceExporter</literal>. Exporting of an ordinary plain
|
|
.NET object as a web service is achieved by registering a custom
|
|
implementation of the <literal>WebServiceHandlerFactory</literal>
|
|
class as the HTTP handler for <literal>*.asmx</literal> requests.</para>
|
|
|
|
<para><ulink
|
|
url="http://www.springframework.net/doc-latest/reference/html/webservices.html">Microsoft
|
|
ASP.NET AJAX</ulink> introduced a new HTTP handler
|
|
<literal>System.Web.Script.Services.ScriptHandlerFactory</literal> to
|
|
allow a Web Service to be invoked from the browser by using
|
|
JavaScript.</para>
|
|
|
|
<para>Spring's integration allows for both Spring.Web and ASP.NET AJAX
|
|
functionality to be used together by creating a new HTTP handler.</para>
|
|
|
|
<sect2 xml:id="exposingWebServices">
|
|
<title>Exposing Web Services</title>
|
|
|
|
<para>The <literal>WebServiceExporter</literal> combined with the
|
|
new HTTP handler exposes PONOs as Web Services in your ASP.NET AJAX
|
|
application.</para>
|
|
|
|
<para>In order for a Web service to be accessed from script, the
|
|
<literal>WebServiceExporter</literal> should decorate the Web
|
|
Service class with the <literal>ScriptServiceAttribute</literal>.
|
|
The code below is taken from the sample application
|
|
Spring.Web.Extensions.Sample, aka the 'AJAX' shortcut in the
|
|
installation. : <programlisting language="myxml">
|
|
<object id="ContactWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
|
|
<property name="TargetName" value="ContactService"/>
|
|
<property name="Namespace" value="http://Spring.Examples.Atlas/ContactService"/>
|
|
<property name="Description" value="Contact Web Services"/>
|
|
<property name="TypeAttributes">
|
|
<list>
|
|
<object type="System.Web.Script.Services.ScriptServiceAttribute, System.Web.Extensions"/>
|
|
</list>
|
|
</property>
|
|
</object>
|
|
|
|
</programlisting></para>
|
|
|
|
<para>All that one needs to do in order to use the
|
|
<literal>WebServiceExporter</literal> is:</para>
|
|
|
|
<para><emphasis> 1. Configure the Web.config file of your ASP.NET AJAX
|
|
application as a Spring.Web application. </emphasis>
|
|
<programlisting language="myxml">
|
|
<sectionGroup name="spring">
|
|
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
|
|
</sectionGroup>
|
|
|
|
</programlisting>
|
|
<programlisting language="myxml">
|
|
<spring>
|
|
<context>
|
|
<resource uri="~/Spring.config"/>
|
|
</context>
|
|
</spring>
|
|
|
|
</programlisting></para>
|
|
|
|
<para><emphasis> 2. Register the HTTP handler and the Spring HttpModule
|
|
under the <literal>system.web</literal> section. </emphasis>
|
|
<programlisting language="myxml">
|
|
<httpHandlers>
|
|
<remove verb="*" path="*.asmx"/>
|
|
<add verb="*" path="*.asmx" validate="false" type="Spring.Web.Script.Services.ScriptHandlerFactory, Spring.Web.Extensions"/>
|
|
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
|
|
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
|
|
</httpHandlers>
|
|
|
|
<httpModules>
|
|
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
|
|
<add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
|
|
</httpModules>
|
|
|
|
</programlisting></para>
|
|
|
|
<para><emphasis> 3. Register the HTTP handler and the Spring HttpModule
|
|
under <literal>system.webServer</literal> section. </emphasis>
|
|
<programlisting language="myxml">
|
|
<modules>
|
|
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
|
|
<add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
|
|
</modules>
|
|
<handlers>
|
|
<remove name="WebServiceHandlerFactory-Integrated" />
|
|
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
|
|
type="Spring.Web.Script.Services.ScriptHandlerFactory, Spring.Web.Extensions"/>
|
|
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
|
|
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
|
|
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
|
|
</handlers>
|
|
|
|
</programlisting></para>
|
|
|
|
<para>You can find a full Web.config file in the example that comes with
|
|
this integration.</para>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="callingWebServices">
|
|
<title>Calling Web Services by using JavaScript</title>
|
|
|
|
<para>A proxy class is generated for each Web Service. Calls to Web
|
|
Services methods are made by using this proxy class. When using the
|
|
<literal>WebServiceExporter</literal>, the name of the proxy class
|
|
is equal to the <literal>WebServiceExporter</literal>'s id.
|
|
<programlisting language="csharp">
|
|
// This function calls the Contact Web service method
|
|
// passing simple type parameters and the callback function
|
|
function GetEmails(prefix, count)
|
|
{
|
|
ContactWebService.GetEmails(prefix, count, GetEmailsOnSucceeded);
|
|
}
|
|
|
|
</programlisting></para>
|
|
</sect2>
|
|
</sect1>
|
|
</chapter> |