Consume WCF WebService

1

I developed a service with C # that consulted a database with certain functions.

I went from AngularJS to Angular2 and here my problems came.

Inside my WCF I have:

[OperationContract]
[WebInvoke(UriTemplate = "/GetCaptaciones", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json , BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Captacion> GetCaptaciones(int id_captador)

From Angular2 I'm making the call to this method like this:

let data = JSON.stringify({ id_captador: 11 });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.post(url + "/GetCaptaciones", data, options).subscribe(data => {
  console.log(data);
});

But I get the error that the input data is not correct. Receive data Raw while the data you expect is JSON . However, if I copy Postman JSON and send everything works correctly.

NetWork tab data

Response Header

Access-Control-Allow-Headers:Accept, Content-Type, Origin
Access-Control-Allow-Methods:GET, PUT, POST, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Allow:POST
Cache-Control:private
Content-Type:text/html; charset=UTF-8
Date:Thu, 27 Apr 2017 21:45:34 GMT
Server:Microsoft-IIS/7.0
Transfer-Encoding:chunked
X-AspNet-Version:4.0.30319

Request Header

Accept:'*/*'
Accept-Encoding:gzip, deflate, sdch
Accept-Language:es-ES,es;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:XXXXXXX
Origin:http://localhost:8100
Referer:http://localhost:8100/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
asked by sioesi 27.04.2017 в 04:05
source

1 answer

0

I think the problem is that

List<Captacion> GetCaptaciones(int id_captador)

expects an int and not an object that is what you send in the json, try to send 11 directly.

    
answered by 28.04.2017 / 19:15
source