Consume same WCF service from angular 2 and Silverlight application

3.6k Views Asked by At

Currently we have one Silverlight application (frontend) with WCF services (backend). Now, we are going replace the Silverlight application with an Angular 2 application without changing the WCF services - only the UI will get changed.

Before starting with Angular 2, we have created a demo application in Angular 2 to verify that WCF services are working with Angular 2, because Silverlight supports basicHttpBinding and for Angular 2, we need to use webHttpBinding. Currently we are facing issues with that.

Is it possible to use one WCF service in Silverlight and Angular 2 in parallel? Please suggest.

2

There are 2 best solutions below

0
Andy On BEST ANSWER

It is possible to use the one wcf service in several ways due to the way they work. You say you're facing issues but you don't say what they are.

WCF services have endpoints. It is the endpoint that defines a connection via basicHttpBinding or webHttpBinding or whatever. You can have multiple endpoints for the one service. These are defined in your config. If you take a look in there, you'll see all your basichttpbinding endpoints. Add one to that for one of your services and give it a go with angular. This is what a webHttpbinding looks like: https://weblogs.asp.net/kiyoshi/wcf-using-webhttpbinding-for-rest-services There is also some advice in there for some common issues. This aspect of WCF is very fiddly to set up. It is conceivable that re-using the same wcf services will not be practical. In which case I would suggest porting the code to web api ( although I think they may have renamed that in current flavour ). It's dead easy to write most stuff because they're just methods with an attribute specifying routing.

0
Sunil On

Yes you can use wcf service first I will suggest please upgrade with angular 4 as there are alots of bugs in angular 2 below are angular 4 service sample code.

angular 4 service

import { Injectable } from '@angular/core';
import {Http,Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';


@Injectable()
export class SampleService {
constructor(private _http: Http) { 

 };
getSample(Id) : Observable<any>{    
  return this._http.get('sample.svc/sample?Id='+Id)
.map((response:Response)=><any>response.json());
};  

}