I have developed a service with C# that queries a database with certain functions.
I moved from AngularJS to Angular2 and here came my problems.
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 am 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 am getting the error that the input data is not correct. It receives data Raw
while the data it expects is JSON
. However, if I copy it in Postman JSON
and send it, 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
I think the problem is that
expect an int and not an object which is what you send in the json, try to send 11 directly.