I am calling a web service api of type httpGet, from angular sends it a parameter of type CopiadoraBusquedaModel and the service retrieves the parameter of type CopiadoraBusqueda, but when i check de parameter on the service web API, the value is null. I have been able to check that the model from angular matches the object from C#. Any ideas?
copiadorabusquedamodel.ts:
export class CopiadoraBusquedaModel {
public codigoCopiadora: string;
public numeroSerie: string;
public numeroInventario: string;
public nombrePersonaEncargada: string;
public idCliente: number;
public idContrato: number;
public idProveedor: number;
public idMarca: number;
public idModelo: number;
public fechaInstalacion: string;
public fechaFinFacturacion: string;
}
service.ts
import { Http, RequestOptions, Headers} from '@angular/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { ListadoCopiadorasModel } from '../../models/listadocopiadoras.model';
import { CopiadoraBusquedaModel } from '../../models/copiadorabusqueda.model';
@Injectable()
export class ListadoCopiadorasService {
headers: Headers;
options: RequestOptions;
private url: any;
// La variable data cachea los datos del servicio.
private data: any;
constructor (private _http: Http) {}
getListadoCopiadorasByFiltro(CopiadoraBusqueda : CopiadoraBusquedaModel): Observable<ListadoCopiadorasModel[]> {
this.url = 'api/copiadoras/get/listadoCopiadorasByFiltro';
this.headers = new Headers({'Content-Type': 'application/json','Accept': 'q=0.8;application/json;q=0.9'});
//this.options = new RequestOptions({ headers: this.headers, params: { 'filtro': JSON.stringify(CopiadoraBusqueda) } });
this.options = new RequestOptions({ headers: this.headers, params: { 'filtro': CopiadoraBusqueda } });
// Si la variable data está vacía se llama al servicio.
// Si tiene datos, se devuelve la variable como observable.
if (!this.data) {
return this._http.get(this.url, this.options)
.map((response: any) =>
response.json() as ListadoCopiadorasModel[])
.do(data => this.data = data);
} else {
return Observable.of(this.data)
.map((response: any) =>
response as ListadoCopiadorasModel[]);
}
}
Copiadoras.Controller.cs: // Some stuff....
[ScriptService]
[RoutePrefix("api/copiadoras")]
public class CopiadorasController: ApiController
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
[Route("get/listadoCopiadorasByFiltro")]
[HttpGet]
public IEnumerable<Copiadora> GetListadoCopiadorasByFiltro(CopiadoraBusqueda filtro)
{
IEnumerable<Copiadora> listadoCopiadoras = null;
using (var servicioCopiadoras = new ServicioCopiadoraClient())
{
listadoCopiadoras = servicioCopiadoras.ObtenerCopiadorasByFiltro(filtro);
}
return listadoCopiadoras.AsEnumerable();
}
CopiadoraBusqueda.cs:
public class CopiadoraBusqueda
{
[DataMember]
public string CodigoCopiadora { get; set; }
[DataMember]
public string NumeroSerie { get; set; }
[DataMember]
public string NumeroInventario { get; set; }
[DataMember]
public string NombrePersonaEncargada { get; set; }
[DataMember]
public Int32 IdCliente { get; set; }
[DataMember]
public Int32 IdContrato { get; set; }
[DataMember]
public Int32 IdProveedor { get; set; }
[DataMember]
public Int32 IdMarca { get; set; }
[DataMember]
public Int32 IdModelo { get; set; }
[DataMember]
public string FechaInstalacion { get; set; }
[DataMember]
public string FechaFinFacturacion { get; set; }
}