I am currently calling the Web Api method from an Angular 2 service (a file called app.service.ts) that returns data, and I can bind this data to my page.
Now I want to call the WCF service from an Angular 2 service (a file called app.service.ts). I have already tried the same as for Web Api. But this leads to an Allow-Access-Origin error. I also pass the headers to solve this problem. But the problem still exists.
import {Http,Response,Headers,RequestOptions} from "@angular/http" import { Observable } from 'rxjs/Rx'; @Injectable() export class HeroService { Hero = []; baseUrl = 'http://192.168.0.4/ITM1.3/Service1.svc/Delete502/'; constructor(private _http: Http) { this.loadHeroes(); } loadHeroes() { let headers = new Headers({ 'Content-Type': 'application/json' },{'Access-Control-Allow-Origin' : '*'},{'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT, DELETE'}); let options = new RequestOptions({ headers: headers }); return this._http.get(this.baseUrl+"Login/ harshad.bhola@etatvasoft.com1 /1",options) .map((response: Response) => { console.log(reponse); let heroData = response.json(); return heroData; }) .do(data => console.log(data)) .catch(this.handleError); } }
I also create one http client class (component) to pass the request header, but still the same error occurs.
So can someone explain how I can call the WCF service and get data from it?
source share