Client Side Code Using WCF - c#

Service.cs
public class StoredProcService : IStoredProcService
{
public int addData(int x, int y)
{
return x + y;
}
}
Error:415 Cannot process the message because the content type
'application/json; charset=utf-8' was not the expected type
'text/xml'aspx
<script type="text/javascript">
$(document).ready(function () {
//$('input[id^="button"]').click(function () {
// alert('You have clicked ' + $(this).val());
Add();
})
function Add() {
alert("sds");
$.ajax({
type: 'POST',
url: '/StoredProcService.svc/addData',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: {"x":"5", "y":"8"},
success: function (data) {
alert(data);
}
});
}
</script>
Markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Server Code" onclick="Button1_Click" />
<input id="button" type="button" value="Client Side" onclick="Add()" />
</div>
</form>
</body>
</html>
Interface:
[ServiceContract]
public interface IStoredProcService
{
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "addData")]
int addData(int x, int y);
}
WebConfig:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>`
<add key="vs:EnableBrowserLink" value="false"/>
<add key="erpConnectionString" value="Data Source=mssql.aksharasoftware.com,1437;Initial Catalog=erp;uid=erp;password=100_erp;Pooling=true;Connection Lifetime=0;Min Pool Size=2;Max Pool Size=400;Connection Timeout=1200;"/>
<add key="PINEDITLICENSEKEY" value="141607143E07144807141606144804144762143E05142A06135162"/>
<add key="owin:AutomaticAppStartup" value="false"/>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" />
<binding name="BasicHttpBinding_ISamplereturn" />
<binding name="BasicHttpBinding_IStoredProcService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50192/Service.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService"
contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
<endpoint address="http://localhost:50192/Samplereturn.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISamplereturn"
contract="ServiceReference2.ISamplereturn"
name="BasicHttpBinding_ISamplereturn" />
<endpoint address="http://localhost:50192/StoredProcService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IStoredProcService"
contract="ServiceReference3.IStoredProcService"
name="BasicHttpBinding_IStoredProcService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" >
<serviceActivations>
<add factory="System.ServiceModel.Activation.WebServiceHostFactory"
relativeAddress="./ServiceReference3/StoredProcService.svc"
service="StoredProcService"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>

By default all the WCF communication occurs using XML.
Try to correct your javascript:
function Add() {
alert("sds");
$.ajax({
type: 'POST',
url: '/StoredProcService.svc/addData',
contentType: 'text/xml; charset=utf-8',
dataType: 'xml',
data: {"x":"5", "y":"8"},
success: function (data) {
alert(data);
}
});

Change the content type in ajax call to contentType: 'text/xml; charset=utf-8' it should work fine.
If you are getting error 400 then try to access URL from browser and correct the URL.

Related

Ajax POST call won't working with WCF

I'm trying to send data through an Ajax POST call to WCF Service
I send the data with jSON
When I tried to make the call, the WCF Service cannot obtain the data sent
Debugging showed that my input parameter was equal to null
This is my source code :
jQuery side
$.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "http://192.168.0.12:25460/Service1.svc/getPost",
type: 'POST',
data: {"value": "test"},
timeout: 5000,
success: function (data, status, xhr)
{
alert('Success: '+data);
},
error: function(x, e)
{
alert(x.status + " " + x.responseText);
}
});
WCF Side
Iservice1.cs
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, UriTemplate = "/getPost?value={value}")]
string getPost(string value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
Service1.svc
public class Service1 : IService1
{
public string getPost(string value)
{
return "Reçu :" + value;
}
}
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxUrlLength="500"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webBehavior">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- Pour éviter la divulgation d'informations de métadonnées, définissez les valeurs ci-dessous sur false avant le déploiement -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- Pour recevoir les détails de l'exception dans les erreurs à des fins de débogage, définissez la valeur ci-dessous sur true. Pour éviter la divulgation d'informations d'exception, définissez-la sur false avant le déploiement -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
Pour parcourir le répertoire racine de l'application Web lors du débogage, définissez la valeur ci-dessous sur true.
Définissez-la sur false avant le déploiement pour ne pas divulguer d'informations du dossier de l'application Web.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Thank you for your help !
Try the following changing. May it will work..
jQuery side
$.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "http://192.168.0.12:25460/Service1.svc/getPost/test",//value in url..
type: 'POST',
// data: {"value": "test"}, remove this line.
timeout: 5000,
success: function (data, status, xhr)
{
alert('Success: '+data);
},
error: function(x, e)
{
alert(x.status + " " + x.responseText);
}
});
WCF Side
Iservice1.cs
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, UriTemplate = "/getPost/{value}")]//change here
string getPost(string value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
I just change your parameter sending approach and put it in URL.

How can I call a Code Behind method with JavaScript?

I want to call a Code Behind method with JS. I already tried [WebMethod]. I referred this link. But my code behind is not getting called. I pasted code below so you can find out actual problem for that.
Javascript
<script type="text/javascript">
function sendMail()
{
var arr = [];
arr.push('foo');
arr.push('bar');
arr.push('bazz');
$.ajax({
type: "POST",
url: "~/Modules/Masters/Email.aspx/SendMail",
data: "{info:arr}", // passing the parameter
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (retValue) {
// Do something with the return value from.Net method
}
});
}
</script>
Code Behind
[WebMethod]
public static string SendMail(string[] info)
{
return "";
}
Does it need any library. I already have
<script src="/js/jquery-1.9.1.js" type="text/javascript"></script> in my .Master file.
try removing the "~" from the url in your ajax call. I don't think javascript can handle it well.
There is a few things that can be wrong, firstly you will need a ScriptManager on your page too!
i am sending mail from pure html page using wcf service may be useful to you please chk this code:
html page:
$(document).ready(function () {
$('#reqinfo').click(function () {
// debugger;
var emailto = document.getElementById("emailid").value;
if (emailto != "") {
$.ajax({
type: "GET",
url: "/EmailService1.svc/EmailService1/emaildata?Email=" + emailto,
// data: dat,
Accept: 'application/json',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
// debugger;
},
error: function (result) {
// debugger;
}
});
}
else {
//your validation message goes here
return false;
}
});
});
Wcf service: IEmailService page
[OperationContract]
[WebInvoke(UriTemplate = "/EmailService1/emaildata?Email={Email}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string emaildata(string Email);
wcf service code page:
public string emaildata(string Email)
{
//your email code.....
}
Web.config code:
<system.webServer>
<defaultDocument>
<files>
<add value="Service1.svc" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script">
<add name="ISAPI64" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
</handlers>
</system.webServer>
<system.serviceModel>
<services>
<service name="SampleService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="IService1" name="samendpoint" behaviorConfiguration="AjaxBehaviour">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true"
automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
and do't forget to add Factory setting in markup of wcf service by right click on wcf service in solution explorer and go to view mark up
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
like in my code i set for example:
<%# ServiceHost Language="C#" Debug="true" Service="PSICMS.EmailService1" CodeBehind="EmailService1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Try this:
[WebMethod]
public static string SendMail(string info)
{
return "";
}
Here info has comma separated values, you can split them and use.
Everything looks fine as far as calling the method. I'm assuming that your path to the method is incorrect. When I use this approach, the [WebMethod] would live in the code-behind of the same page, so I would use url: "Email.aspx/SendEmail I would also add an error handler to your $.ajax call to help with debugging. add this after your success handler. error: function(a,b,c){alert(a.responseText);} this should tell you what the problem is. You also don't need a script manager to make any of this work.

Web Service WCF and Javascript

I have 2 projects (WCF project and Asp.Net project). I followed this tutorial here .
In this tutorial, we realize all in one project (see sources here).
I have a reference to my WCF project in Web project.
I try to display a value in my alert but there is nothing.
Here is my Service1.svc :
namespace WSSage100{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public string GetData2(int value)
{
return string.Format("You entered: {0}", value);
}
public string[] GetUser(string Id)
{
return new User().GetUser(Convert.ToInt32(Id));
}
public string GetTEST()
{
return "OKKKKKKKK";
}
}
Here is IService1.cs :
namespace WSSage100
{
[XmlSerializerFormat]
[ServiceContract(Namespace ="WSSage100")]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json)]
string GetData(int value);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
string GetData2(int value);
[OperationContract]
[WebInvoke(Method = "POST",BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat = WebMessageFormat.Json)]
string[] GetUser(string Id);
[OperationContract]
[WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json)]
string GetTEST();
Here is my web page (aspx) with JavaScript code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="JavaScript/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
var Type;
var Url;
var Data;
var ContentType;
var DataType;
var ProcessData;
function WCFJSON() {
var userid = "1";
Type = "POST";
Url = "Service1.svc/GetUser";
Data = '{"Id": "' + userid + '"}';
ContentType = "application/json; charset=utf-8";
DataType = "json"; varProcessData = true;
CallService();
}
function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
Type = null;
varUrl = null;
Data = null;
ContentType = null;
DataType = null;
ProcessData = null;
}
function ServiceSucceeded(result) {
if (DataType == "json") {
resultObject = result.GetUserResult;
for (i = 0; i < resultObject.length; i++) {
alert(resultObject[i]);
}
}
}
function ServiceFailed(xhr) {
alert(xhr.responseText);
if (xhr.responseText) {
var err = xhr.responseText;
if (err)
error(err);
else
error({ Message: "Unknown server error." })
}
return;
}
$(document).ready(
function () {
WCFJSON();
}
);
</script>
<style type="text/css">
#form1 {
height: 255px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div></div>
</form>
</body>
</html>
Here is Service1.svc in my Web project :
<%# ServiceHost Language="C#" Debug="true" Service="WSSage100.Service1"%>
Here is my web.config in my Web project :
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<client>
<endpoint address="http://localhost:52768/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WebServiceSage100.IService1"
name="BasicHttpBinding_IService1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<services>
<service name="WSSage100.Service1">
<endpoint address="" binding="webHttpBinding" contract="WSSage100.IService1">
</endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
Brian, localhost:52768/Service1.svc display
I have this error when I use Inspect Element
I'm new in this domain and sorry for my bad english.
I had 2 projects in my solution, the WCF and an application console (GettingStartedHost) that will do to turn back the web service.
I also added the connectionstrings in app.config of the GettingStartedHost project and now it works well.

Calling a local WCF service via Scriptish or Greasemonkey

I'm trying to expose a local WCF service that checks to see if a file exists in my database that can be accessed from a Scriptish script.
Is it possible to call a local URL from Scriptish or Greasemonkey (GET or POST)? I've created a WCF service hosted in IIS on my local machine, and the service is working fine. However, when I try to call the service from Scriptish the Network tab in Chrome/Firefox just says the following:
Request URL: http://localhost/service/service.svc/MatchPartial
Request Method: OPTIONS
Status code: 405 Method Not Allowed
Here is my ajax call:
$.ajax({
url: 'http://localhost/service/service.svc/MatchPartial',
type: 'POST',
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
processData: true,
data: '{ "partialFilename": "testing" }',
success: function (result) {
console.log(result);
}
});
My method is decorated with:
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public int MatchPartial(string partialFilename)
{
...
}
I have the following above my service class:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
I've tried adding the following to my service with no luck:
[WebInvoke(Method = "OPTIONS", UriTemplate = "*")]
public void GetOptions()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
}
I feel like I've tried everything. Any help would be appreciated!
I figured out how to do it via a GET request thanks to M.Babcock for pushing me in that direction (unimportant parts intentionally left out to save space).
Service.svc:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public bool MatchPartial(string partialFilename)
{
...
}
}
Web.config:
<configuration>
...
...
<system.web>
<compilation debug="true"
targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<!-- IMPORTANT FOR THIS TO WORK USING JQUERY GET OR AJAX -->
<add name="Access-Control-Allow-Origin"
value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.serviceModel>
<services>
<service name="MyNamespace.Services.WCF.Service">
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration=""
contract="MyNamespace.Core.Interfaces.IService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Service" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<!-- For Debugging --->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
Here's how to do it in Scriptish:
var service = "http://localhost/service/service.svc";
GM_xmlhttpRequest({
method: "GET",
url: service + "/MatchPartial?partialFilename=" + filename,
headers: { "Accept": "application/json" },
onload: function (result) {
if (result != null && result.status == 200 && result.responseJSON == true) {
videoFrame.remove();
}
},
onerror: function (res) {
GM_log("Error!");
}
});
Plain ol' jQuery:
$.get("service", { partialFilename: filename }, function (result) {
if (result == true) {
videoFrame.remove();
}
});

Why WCF service is not getting called in AJAX auto complete extender?

I am trying to consume a wcf service in auto complete extender but it is not getting called but the same thing i tried in web services it's working fine there.
Below is my sample code
In App_Code/AutoCompleteWCF.cs
[ServiceContract]
public interface IAutoCompleteWCF
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "POST",ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json)]
string[] GetCompletionList(string prefixText, int count );
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AutoCompleteWCF : IAutoCompleteWCF
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "POST", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json)]
public string[] GetCompletionList(string prefixText, int count)
{
string[] str = new string[5];
str[0] = prefixText + "A";
str[1] = prefixText + "B";
str[2] = prefixText + "C";
str[3] = prefixText + "D";
str[4] = prefixText + "E";
return str;
}
}
AutoCompleteWCF.svc
<%# ServiceHost Language="C#"Debug="true" Service="AutoCompleteWCF" CodeBehind="~/App_Code/AutoCompleteWCF.cs" %>
Web.confifg
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="AutoComplete" behaviorConfiguration="ServiceBehavior">
<endpoint address="F" binding="webHttpBinding" contract="IAutoCompleteWCF" behaviorConfiguration="ServiceAspNetAjaxBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
</configuration>
WebForm1.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AutoCompleteDemo.WebForm1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ccl" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ccl:ToolkitScriptManager ID="ScriptManager1" runat="server"></ccl:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ccl:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
BehaviorID="AutoCompleteEx"
TargetControlID="TextBox1"
ServicePath="AutoCompleteWCF.svc"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="false">
</ccl:AutoCompleteExtender>
</div>
</form>
</body>
</html>

Categories