Теперь я получил это текстовое поле example2 с автозаполнением.Вот что я исправил:
в javascript, удалите косую черту (/):
$('#example2').autocomplete(url + "ChatService.svc/GetCompletions");
web.config, заменен новым без странных твиков:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="myBehavior" name="YourCompany.Services.MyService">
<endpoint address="" binding="webHttpBinding" contract="YourCompany.Services.IMyService" behaviorConfiguration="myBehavior"/>
</service>
</services>
</system.serviceModel>
интерфейс:
[ServiceContract(Namespace = "YourCompany.Services")]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "GetCompletions?q={q}", ResponseFormat = WebMessageFormat.Json)]
string GetCompletions(string q);
}
очень важный трюк в методе класса GetCompletions
для выполнения ожидаемого формата автозаполнения плагина:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyService
{
public string GetCompletions(string q)
{
List<String> words = new List<String> {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December", "Yammer", "Yaw", "Yawn", "Auspiscious",
"Arbitrage", "Arbiter", "Arbor", "Ardor", "Ardent",
"Concrete", "Conscious", "Uptight", "Uplevel", "Friend",
"Depend", "Deepend", "Deepen", "Decommit", "Right", "Now",
"Knowledge", "Knight", "Know", "Knickers", "Wow", "Holy",};
var selection = from candidate in words
where candidate.ToUpper().StartsWith(q.ToUpper())
select candidate;
//autocomplete funny format
return string.Join("\n", selection.ToArray());
}
}