Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 来自angular的WCF Post Json_C#_Json_Angular_Wcf - Fatal编程技术网

C# 来自angular的WCF Post Json

C# 来自angular的WCF Post Json,c#,json,angular,wcf,C#,Json,Angular,Wcf,我正在尝试post方法从angular向wcf发送json数据。Angular正在以json格式发送数据,但wcf将其作为空对象接收。可以使用get方法发送json。正在对按钮单击事件调用GetData方法 角分量 WCF Service.svc.cs WCF.cs 删除BodyStyle=WebMessageBodyStyle.WrappedRequest,然后就可以开始了 import { Component } from '@angular/core'; import { HttpClie

我正在尝试post方法从angular向wcf发送json数据。Angular正在以json格式发送数据,但wcf将其作为空对象接收。可以使用get方法发送json。正在对按钮单击事件调用GetData方法

角分量 WCF Service.svc.cs WCF.cs
删除
BodyStyle=WebMessageBodyStyle.WrappedRequest
,然后就可以开始了

import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {


  constructor(private httpClient: HttpClient){

  }


  getData(){
    this.httpClient.post('http://localhost:3292/examservice.svc/jsontest',{
      RollNumber: '41',
      Name: 'Test'
    })
    .subscribe(
      (data:any) => {
        console.log(data);
      }
    )

  }
}
namespace Service
{

    public class Service : IService
    {
        public Student jsont(Student s)
        {

            return s;
        }
   }
}
namespace Service
{

    [ServiceContract]
    public interface IService
    {

[OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "jsontest", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Student jsont(Student s);
    }


    [DataContract]
    public class Student
    {
        [DataMember]
        public string RollNumber { get; set; }
        [DataMember]
        public string Name { get; set; }
    }
}