I am attempting to connect to a WCF web service with Ionic4. I can connect to the web service using regular ajax but I cannot with Ionic's HTTPClient. The error that I am receiving is that the webservice is not configured to accept connections from the server.
Below is the code from the web server that is set to accept connections from foreign servers. The other section of code is the connection to the webserver from the Ionic application.
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With,Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
constructor(private http: HttpClient) { }
query() {
this.data = this.http.get('http://localhost:55283/LOAService.svc/test');
this.data.subscribe(data => {
this.result = data;
});
}
}
As I can connect from ajax I can only assume that the problem is with the Ionic code. Am I right to assume this?