I'm in a proyect where I have to fill a textbox (as if it was a select control) with data requested from a Web Service while the user is writing in the textbox.
The web service is developed in the same solution.
The problem is when I make a request from the client-side it throws me:
"Failed to load http://.../wsConsultaAfiliados.asmx: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I've searching for a while and I read that is a problem of CORS. However, I don't understand why. I'm requesting the data to the web service from the client-side which are in the same domain.
For what I searched I understand that CORS is for security reasons when you ask data from X domain to Y domain.
It's the first time I consume web service and I'm a bit lost about the scheme I should follow.
Add code
public class wsConsultaAfiliados : System.Web.Services.WebService
{
/// <summary>
/// Busca una lista de Afiliados que coincidan con los parámetros de entrada. Devuele DataTable.
/// </summary>
/// <returns></returns>
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public DataTable ConsultarAfiliados(string oPrefixText)
{
var listaAfiliados = GetAfiliados(oPrefixText);
return listaAfiliados;
}
/// <summary>
/// Devuelve un DataTable con Codigo y Nombre del afiliado.
/// </summary>
/// <param name="oPrefixText"></param>
/// <returns></returns>
public DataTable GetAfiliados(string oPrefixText)
{
negPrevision neg = new negPrevision();
return neg.obtenerAfiliadosPorNombre(oPrefixText);
}
}
Here's the code from the web services. It ask for data to the logic layer.