Origem http: // localhost não é permitido pelo Access-Control-Allow-Origin
Estou tentando chamar um webservice da minha máquina local. Mas recebo os seguintes erros no console do Chrome:http://www.test.com/service.svc/api/?cid=1 405 (Method Not Allowed) XMLHttpRequest cannot load http://www.test.com/service.svc/api/?cid=1.<br>Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Meu URL de teste local é:http://localhost/welcome/html/index.html
Quando eu carrego meu código no domínio real e ligo para o serviço da Web a partir dele, é claro que funciona.
Eu já tentei mudar os cabeçalhos de controle de acesso, mas isso não ajuda.
Namespace RestService
Public Class service
Implements Iservice
Public Function GetProvinces(ByVal cid As String) As AjaxControlToolkit.CascadingDropDownNameValue() Implements Iweddingservice.GetProvinces
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "DELETE, POST, GET, OPTIONS")
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*")
Dim MyConnection As SqlConnection = GetConnection()
Dim cmd As New SqlCommand("SELECT provinceid,title FROM provinces WHERE CountryID=@CountryID ORDER BY title ASC", MyConnection)
cmd.Parameters.Add(New SqlParameter("@CountryID", cid))
Dim values As New List(Of CascadingDropDownNameValue)
Try
MyConnection.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
values.Add(New CascadingDropDownNameValue(reader("title").ToString, reader("provinceid").ToString))
End While
Catch ex As Exception
Finally
MyConnection.Close()
End Try
Return values.ToArray
End Function
End Class
End Namespace