Bonjour à tous,
Alors voilà j'ai un problème que je n'arrive pas à résoudre (et j'espère que l'un d'entre vous pourra m'aider :-)):
J'ai créé un Web Service Autocomplete.asmx, que j'appel via l'une de mes pages, et qui va chercher des données dans ma base de données. Tout fonctionne parfaitement bien sous Visual Studio 2010.
Le problème c'est que quand je passe le tout sur mon serveur (Windows Server 2008 avec IIS 7, Framework 4.0), il ne se passe strictement rien!
Bref je commence à vraiment m'arracher les cheveux! J'espère que quelqu'un pourra m'aider!!!
Code du service:
Code de ma page:
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 Imports System Imports System.Collections Imports System.Linq Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Xml.Linq Imports System.Collections.Generic Imports System.Data Imports System.Data.SqlClient ' To allow this Web Service to be called from script, using ASP.NET AJAX, ' uncomment the following line. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class AutoComplete1 Inherits System.Web.Services.WebService Dim cn As New SqlClient.SqlConnection() Dim ds As New DataSet Dim dt As New DataTable <WebMethod()> _ Public Function GetCompletionList(ByVal prefixText As String, _ ByVal count As Integer) As List(Of String) 'ADO.Net Dim strCn As String = "Data Source=.\SQLEXPRESS;Initial Catalog=BDD;User Id=user;Password=mdp;" cn.ConnectionString = strCn Dim cmd As New SqlClient.SqlCommand cmd.Connection = cn cmd.CommandType = CommandType.Text 'Compare String From Textbox(prefixText) 'AND String From Column in DataBase(CompanyName) 'If String from DataBase is equal to String from TextBox(prefixText) 'then add it to return ItemList '-----I defined a parameter instead of passing value 'directly to prevent SQL injection--------' cmd.CommandText = "SELECT id_article, code FROM article Where code like @myParameter" cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%") cn.Open() Dim customers As List(Of String) = New List(Of String) Dim sdr As SqlDataReader = cmd.ExecuteReader While sdr.Read Dim item As String item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr("code").ToString, sdr("id_article").ToString) customers.Add(item) End While cn.Close() Return customers End Function End Class
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
45
46
47
48
49
50
51
52
53
54
55
56
57 [...] <asp:HiddenField ID="id_article" runat="server" /> <asp:TextBox ID="code" autocomplete ="off" AutoPostBack="true" runat="server" Width="150px" Height="20px" placeholder="Code" OnTextChanged="RemplirPrix" /> [...] <script type = "text/javascript"> function ClientItemSelected(sender, e) { $get("<%=id_article.ClientID %>").value = e.get_value(); } </script> <ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server" EnableCaching="true" BehaviorID="AutoCompleteEx" MinimumPrefixLength="2" TargetControlID="code" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" OnClientItemSelected = "ClientItemSelected" CompletionInterval="10" CompletionSetCount="20" DelimiterCharacters="" ShowOnlyCurrentWordInCompletionListItem="true"> <Animations> <OnShow> <Sequence> <%-- Make the completion list transparent and then show it --%> <OpacityAction Opacity="0" /> <HideAction Visible="true" /> <%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%> <ScriptAction Script="// Cache the size and setup the initial size var behavior = $find('AutoCompleteEx'); if (!behavior._height) { var target = behavior.get_completionList(); behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" /> <%-- Expand from 0px to the appropriate size while fading in --%> <Parallel Duration=".4"> <FadeIn /> <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" /> </Parallel> </Sequence> </OnShow> <OnHide> <%-- Collapse down to 0px and fade out --%> <Parallel Duration=".4"> <FadeOut /> <Length PropertyKey="height" StartValueScript= "$find('AutoCompleteEx')._height" EndValue="0" /> </Parallel> </OnHide> </Animations> </ajaxToolkit:AutoCompleteExtender>
Partager