我試圖從本地計算機調用Web服務。但我得到在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.
訪問控制 - 允許來源不允許訪問http:// localhost
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
我的本地測試網址是: http://localhost/welcome/html/index.html
當我我的代碼上傳到實際的域,並呼籲從那裏的web服務,但它ofcourse工作。
我已經嘗試更改訪問控制標題,但這沒有幫助。
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 [email protected] 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