Bonjour,

j'essaie en vain de développer une appli de test faisant appel à un webservice via Ajax. Le but de mon test :
- afficher une page web avec un bouton
- sur le clic du bouton, faire appel à une fonction du webservice qui renvoie un message et l'heure courante

je me suis basé sur :
http://msdn.microsoft.com/fr-fr/library/bb532367.aspx
http://www.asp.net/ajax/documentatio...XTutorial.aspx (pour le web.config)


--------------------------------------------------------------------------
VS2005 - Application Web ASP.NET
le code du webservice se trouve dans mon projet web
j'ai installé les extensions Ajax pour VS (System.Web.Extensions.dll entre autres)
--------------------------------------------------------------------------

exécution en DEBUG, mes erreurs :

Erreur d'exécution Micrositf JScript: 'Type' est indéfini
sur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Type.registerNamespace('AjaxTEST');
dans http://localhost:[mon_port]/WSAjax.asmx/jsdebug

Erreur d'exécution Micrositf JScript: 'Sys' est indéfini
sur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Sys.WebForms.PageRequestManager._initialize('scriptManager', document.getElementById('Form1'));
dans http://localhost:[mon_port]

quelqu'un voit de quoi il s'agit ?

l'arborescence des fichiers :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
js/
   AjaxTEST.js
default.aspx
   default.aspx.cs
   default.aspx.designer.cs
web.config
WSAjax.asmx
   WSAjax.asmx.cs
default.aspx.cs = pas de modification de ma part

default.aspx
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="AjaxTEST._Default" %>
 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  Namespace="System.Web.UI" TagPrefix="asp" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head id="Head1" runat="server">
  <style type="text/css">
            body {  font: 11pt Trebuchet MS;
                    color: #000000;
                    padding-top: 72px;
                    text-align: center }
 
            .text { font: 8pt Trebuchet MS }
        </style>
  <title>Using AJAX Enabled ASP.NET Service</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:ScriptManager runat="server" ID="scriptManager">
      <services><asp:ServiceReference path="~/WSAjax.asmx" /></services>
      <scripts><asp:ScriptReference Path="~/js/AjaxTEST.js" /></scripts>
    </asp:ScriptManager>
    <div>
      <h3>
        Using AJAX Enabled ASP.NET Service</h3>
      <table>
        <tr align="left">
          <td>
            Click to call the Hello World service:</td>
          <td>
            <button id="Button1" onclick="OnClickGreetings(); return false;">Greetings</button>
          </td>
        </tr>
      </table>
    </div>
  </form>
  <hr />
  <div>
    <span id="Results"></span>
  </div>
</body>
</html>
WSAjax.asmx.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
 
namespace AjaxTEST
{
  /// <summary>
  /// Description résumée de WSAjax
  /// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.Web.Script.Services.ScriptService]
  public class WSAjax : System.Web.Services.WebService
  {
 
    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string Greetings()
    {
      string serverTime =
          String.Format("Current date and time: {0}.", DateTime.Now);
      string greetings = "Hello World! <br/>" + serverTime;
      return greetings;
    }
  }
}
AjaxTEST.js
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
var AjaxProxy;
 
// Initializes global and proxy default variables.
function pageLoad()
{
    // Instantiate the service proxy.
    AjaxProxy = new AjaxTEST.WSAjax();
 
    // Set the default call back functions.
    AjaxProxy.set_defaultSucceededCallback(SucceededCallback);
    AjaxProxy.set_defaultFailedCallback(FailedCallback);
}
 
 
// Processes the button click and calls
// the service Greetings method.  
function OnClickGreetings()
{
    var greetings = AjaxProxy.Greetings();
}
 
// Callback function that
// processes the service return value.
function SucceededCallback(result)
{
    var RsltElem = document.getElementById("Results");
    RsltElem.innerHTML = result;
}
 
// Callback function invoked when a call to 
// the  service methods fails.
function FailedCallback(error, userContext, methodName) 
{
    if(error !== null) 
    {
        var RsltElem = document.getElementById("Results");
 
        RsltElem.innerHTML = "An error occurred: " + 
            error.get_message();
    }
}
 
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
Web.config
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?><configuration>
 
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <compilation debug="true">
		<assemblies>
			<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies></compilation>
        <authentication mode="Windows"/>
	<httpHandlers>
		<remove verb="*" path="*.asmx"/>
		<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
	</httpHandlers>
    </system.web>
</configuration>